Author |
Message
|
mahek |
Posted: Thu Nov 30, 2006 11:52 am Post subject: XML PARENT TAG |
|
|
Voyager
Joined: 10 Sep 2004 Posts: 87
|
Hi all,
How to find the parent tag name in the xml document using esql.
for example
<A>
<B>B</B>
<C>C</C>
</A>
I want to get the name of the parent tag as A |
|
Back to top |
|
 |
JosephGramig |
Posted: Thu Nov 30, 2006 11:59 am Post subject: |
|
|
 Grand Master
Joined: 09 Feb 2006 Posts: 1244 Location: Gold Coast of Florida, USA
|
|
Back to top |
|
 |
mahek |
Posted: Thu Nov 30, 2006 12:11 pm Post subject: |
|
|
Voyager
Joined: 10 Sep 2004 Posts: 87
|
Hi Joseph,
I am getting XML as the result instead of getting the result as A while using the code mentioned in the document |
|
Back to top |
|
 |
JosephGramig |
Posted: Thu Nov 30, 2006 12:28 pm Post subject: |
|
|
 Grand Master
Joined: 09 Feb 2006 Posts: 1244 Location: Gold Coast of Florida, USA
|
So you tried,
FIELDNAME(InputRoot.XML.*[1])
To find out what the name is of the first (and only) child of the XML document? _________________ Joseph
Administrator - IBM WebSphere MQ (WMQ) V6.0, IBM WebSphere Message Broker (WMB) V6.1 & V6.0
Solution Designer - WMQ V6.0
Solution Developer - WMB V6.1 & V6.0, WMQ V5.3 |
|
Back to top |
|
 |
mahek |
Posted: Thu Nov 30, 2006 12:58 pm Post subject: same problem |
|
|
Voyager
Joined: 10 Sep 2004 Posts: 87
|
it is still giving me the value as XML |
|
Back to top |
|
 |
kimbert |
Posted: Thu Nov 30, 2006 12:59 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
I am getting XML as the result instead of getting the result as A while using the code mentioned in the document |
I suspect that your input document has an xml declaration before the root tag. You need to qualify that path with the type of element that you are seeking.
Something like
Code: |
FIELDNAME(InputRoot.XML.(XML.Element)*[1]) |
( not tested ) |
|
Back to top |
|
 |
mahek |
Posted: Thu Nov 30, 2006 1:06 pm Post subject: |
|
|
Voyager
Joined: 10 Sep 2004 Posts: 87
|
Hi kimbert, joseph ,
Thanks a lot it works now when i use
FIELDNAME(InputRoot.XML.(XML.Element)*[1]).
Thanks |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Nov 30, 2006 1:22 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
But of course, you really are using InputRoot.XMLNS or InputRoot.XMLNSC because of course you aren't using the deprecated XML parser and of course you are using version 5.x or 6.x and not the unsupported 2.1. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
JosephGramig |
Posted: Thu Nov 30, 2006 2:12 pm Post subject: |
|
|
 Grand Master
Joined: 09 Feb 2006 Posts: 1244 Location: Gold Coast of Florida, USA
|
Observe the behaviour in this code snipit:
Code: |
DECLARE iRootTag INTEGER CARDINALITY(InputRoot.XMLNSC.*[]);
DECLARE szRootTag CHARACTER;
FOR pXML AS InputRoot.XMLNSC.*[] DO
SET szRootTag = FIELDNAME(pXML);
END FOR;
|
You will see that you get two tags. The XML declaration and the one you want. I guess you could always just look at the second element. _________________ Joseph
Administrator - IBM WebSphere MQ (WMQ) V6.0, IBM WebSphere Message Broker (WMB) V6.1 & V6.0
Solution Designer - WMQ V6.0
Solution Developer - WMB V6.1 & V6.0, WMQ V5.3 |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Nov 30, 2006 3:06 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
JosephGramig wrote: |
Observe the behaviour in this code snipit:
Code: |
DECLARE iRootTag INTEGER CARDINALITY(InputRoot.XMLNSC.*[]);
DECLARE szRootTag CHARACTER;
FOR pXML AS InputRoot.XMLNSC.*[] DO
SET szRootTag = FIELDNAME(pXML);
END FOR;
|
You will see that you get two tags. The XML declaration and the one you want. I guess you could always just look at the second element. |
Not reliable. Go through the children first level and check the type against the element type. That should always give you the tag on a well formed XML doc.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|