|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
ESQL: Accesing XML fields |
« View previous topic :: View next topic » |
Author |
Message
|
chaitanyauk |
Posted: Sun Feb 17, 2019 4:33 am Post subject: ESQL: Accesing XML fields |
|
|
Apprentice
Joined: 16 Apr 2017 Posts: 30
|
Hello Experts,
I trying to access some field value in XML message through ESQL code(using XMLNSC parser), but not able to access the value:
below is my Sample XML:
Code: |
<ZXML xsi:schemaLocation="http://www.abc.com/zxml trans.xsd" xmlns="http://www.abc.com/zxml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header>
<Data>
<Key>
<ID>12345</ID>
</Key>
</Data>
</Header>
</ZXML> |
below is my ESQL code, in none of the way was I able to fetch the data:
Code: |
SET val1 = InputRoot.XMLNSC.ZXML.Header.Data.Key.ID;
SET val2 = InputRoot.XMLNSC.*.Header.Data.Key.ID;
SET val3 = InputRoot.XMLNSC.(XMLNSC.Element)Header.Data.Key.ID;
SET val4 = InputRoot.XMLNSC.*.*.*.*.Header.Data.Key.ID; |
Also tried removing the namespace, as given here:
https://developer.ibm.com/answers/questions/210953/how-to-remove-or-delete-namespaces-from-xmlnsc-dom/
Code: |
SET OutputRoot.XMLNSC.*:ZXML.(XMLNSC.NamespaceDecl)* = NULL;
SET OutputRoot.XMLNSC.*:ZXML NAMESPACE = '';
SET OutputRoot.XMLNSC.*:ZXML.(XMLNSC.Attribute)xsi = NULL;
SET OutputRoot.XMLNSC.*:ZXML.(XMLNSC.Attribute)schemaLocation = NULL; |
I was able to remove the namespace: xmlns="http://www.abc.com/zxml", whereas other namespaces remained as it is.
Tried to fetch fieldvalue of the first element, got null;
Code: |
SET fv = FIELDNAME(InputRoot.XMLNSC.ZXML); --gives null |
Is there any thing wrong with namespace?
Any help in this regard would be great.
 |
|
Back to top |
|
 |
timber |
Posted: Mon Feb 18, 2019 1:42 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Please add a Trace node in your message flow. Put it immediately after the input node, and set the Pattern to ${Root}. Post the output in this thread, and I can then explain what is happening. |
|
Back to top |
|
 |
chaitanyauk |
Posted: Mon Feb 18, 2019 4:21 am Post subject: |
|
|
Apprentice
Joined: 16 Apr 2017 Posts: 30
|
Solved!
Was able to fetch value with below code:
Quote: |
SET val1 = InputRoot.XMLNSC.*:ZXML.*:Header.*:Data.*:Key.*:ID; |
XML elements inherit the parent element namespaces by default unless it is specified explicitly.
Thank you! |
|
Back to top |
|
 |
timber |
Posted: Mon Feb 18, 2019 5:07 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Glad you got it working, but this statement is not accurate:
Quote: |
XML elements inherit the parent element namespaces by default unless it is specified explicitly |
If you believe that, you will end up very confused next time you deal with an XML message. I suggest that you check out an XML tutorial - the rules are not difficult to understand. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|