|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Parsing a Marked up Xml string inside an xml document |
« View previous topic :: View next topic » |
Author |
Message
|
MasterMind |
Posted: Sun May 15, 2011 1:22 pm Post subject: Parsing a Marked up Xml string inside an xml document |
|
|
Newbie
Joined: 09 Nov 2010 Posts: 9
|
Hi ,
I am looking for possible options to parse the following content
<NS1:Root xmlns:NS1="http://abc.com">
<NS1:E1>
<NS1:e2>xxx</NS1:e2>
<NS1:e3>xxx</NS1:e3>
<NS1:Root1 >
<testdata xmlns="http://www.bcd.com" xmlns:prdate="http://www.abc.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.abc.com/payload/testdata.xsd ><item>1234</item><component_type>N</component_type><value>5350</value></testdata>
</NS1:Root1 >
</NS1:E1>
</NS1:Root >
As you see thee message has a marked up xml included under root1, i am able to fetch it into a environment variable/output root , but i am not able to parse the elements under root (Environment.variable.Data.XMLNSC.testdata.item)
Its not able to understand the xpath.
I got the content of Root1 from input xml into a string and than using Create , parsed it through XMLNSC parser.
its not allowing me to parse it directly using xpath, is it the issue with the namespace declerations which are redundent, can we remove it in any way. I dont want to use the substring option.
And there is no scope for changing the input xml (its being sent from an existing application). please suggest.
Regards,
MM |
|
Back to top |
|
 |
fjb_saper |
Posted: Sun May 15, 2011 8:00 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Quote: |
I got the content of Root1 from input xml into a string and than using Create , parsed it through XMLNSC parser.
its not allowing me to parse it directly using xpath, is it the issue with the namespace declerations which are redundent, can we remove it in any way. I dont want to use the substring option.
And there is no scope for changing the input xml (its being sent from an existing application). please suggest. |
Working as designed. Why would you want to use xpath against something that is not yet in the message / environment tree?
Seems you solved the problem and got the embedded XML into a tree using create parse which is the right way to handle this...
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
mqjeff |
Posted: Mon May 16, 2011 2:41 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
As fj says, until you have instructed Broker to treat that string as an XML document and parse it, it is still just a string which is a single value, and thus you can't access pieces of it as if they were part of a logical message tree.
Whoever is producing this XML document is probably doing the wrong thing. They probably do not intend to be producing this data as a value and are somehow expecting that it will be parsed as XML data.
However, whatever is being done to create it is being done the wrong way and so it comes out this way. |
|
Back to top |
|
 |
MasterMind |
Posted: Mon May 16, 2011 10:08 am Post subject: |
|
|
Newbie
Joined: 09 Nov 2010 Posts: 9
|
It was fairly simple, i was able to parse the xml as below
DECLARE xmlString CHARACTER InputRoot.XMLNSC.ns1:Root.ns1:E1.ns1:Root1;
CREATE LASTCHILD OF Environment.Variable.Data DOMAIN ('XMLNSC') PARSE (xmlString CCSID 1208);
the env tree can now be parsed. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon May 16, 2011 10:27 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
MasterMind wrote: |
It was fairly simple, i was able to parse the xml as below
DECLARE xmlString CHARACTER InputRoot.XMLNSC.ns1:Root.ns1:E1.ns1:Root1;
CREATE LASTCHILD OF Environment.Variable.Data DOMAIN ('XMLNSC') PARSE (xmlString CCSID 1208);
the env tree can now be parsed. |
Yes, this is the right way to parse this data. But again, you probably should review whether this data is expected to be a single string like it is...
And you should also be aware that passing this kind of xml document within another xml document can lead to difficulties if care isn't taken. |
|
Back to top |
|
 |
MasterMind |
Posted: Mon May 16, 2011 10:36 am Post subject: |
|
|
Newbie
Joined: 09 Nov 2010 Posts: 9
|
agreed, but with a little bit of care we can parse the xml easily. |
|
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
|
|
|
|