ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » PARSE XML inside XML field

Post new topic  Reply to topic Goto page 1, 2  Next
 PARSE XML inside XML field « View previous topic :: View next topic » 
Author Message
sugan87
PostPosted: Thu Aug 04, 2016 1:55 am    Post subject: PARSE XML inside XML field Reply with quote

Novice

Joined: 14 Jul 2016
Posts: 18

How to parse the XML inside the XML field,

ex.,

<RootTextData>
<TextData><?xml version="1.0"?> <FormData> <FormContent> <NamedInsured>Test1</NamedInsured> </FormContent> </FormData>
</TextData>
<RootTextData>
Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Aug 04, 2016 3:45 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Don't.

Or use CDATA if you're really insistent on doing something that's a poor idea.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
timber
PostPosted: Thu Aug 04, 2016 4:18 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1292

This:
Code:
<RootTextData>
<TextData><?xml version="1.0"?> <FormData> <FormContent> <NamedInsured>Test1</NamedInsured> </FormContent> </FormData>
</TextData>
<RootTextData>
is not valid XML. For the reason why, see: https://www.w3.org/TR/REC-xml/#syntax
...or read almost any tutorial on XML and escaping of markup.
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Aug 04, 2016 4:43 am    Post subject: Re: PARSE XML inside XML field Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

sugan87 wrote:
How to parse the XML inside the XML field,


You can't.

Because you can't write XML like that.

Paste that example into XMLSpy or similar and ask it if that's well formed XML. Depending on the product, you'll get "Hell no!" or a red box.

If you really want to do this, the embedded XML needs to be in a CDATA section or base64 encoded. But unless the document it's embedded in has a lot more data than your example shows then this is a really, really, really stupid design.

If it does have a lot more data than shown in your example it's just a really, really stupid design.

Ask whoever's producing this XML how they're doing it. I'll bet they're doing it by concatenating the data together as strings rather than using an XML parser because I can't think of a commercial (or indeed worthwhile open source) parser that would serialize it like that without throwing a bunch of errors.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Aug 04, 2016 4:47 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Note, instead of doing this, you could simply remove the "<?xml version="1.0"?> " tag, and you'd have perfectly reasonable XML.
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Aug 04, 2016 4:54 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

mqjeff wrote:
Note, instead of doing this, you could simply remove the "<?xml version="1.0"?> " tag, and you'd have perfectly reasonable XML.


You'd have well formed really, really (or really, really, really) stupid XML.

I strongly suspect the "design" here is attempting to bulk up a series of pre-existing XML documents into a single one.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
sugan87
PostPosted: Thu Aug 04, 2016 5:36 am    Post subject: Reply with quote

Novice

Joined: 14 Jul 2016
Posts: 18

sorry masters, i have incorrectly posted the XML editor result.

The original XML is
<RootTextData>
<TextData>&lt;?xml version="1.0"?&gt; &lt;FormData&gt; &lt;FormContent&gt;&lt;NamedInsured&gt;Test1&lt;/NamedInsured&gt; &lt;/FormContent&gt; &lt;/FormData&gt;
</TextData>
</RootTextData>
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Aug 04, 2016 5:54 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

sugan87 wrote:
sorry masters, i have incorrectly posted the XML editor result.


Ok, so it's a CDATA section with no CDATA tags. I'll give that a really, really stupid.

I stand by my comments on the design. Why are you doing this?



_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
timber
PostPosted: Thu Aug 04, 2016 5:58 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1292

The XMLNSC parser is doing exactly what the Java XML parser would do. It is taking the content of the <TextData> tag and creating a CHARACTER field from it. Your challenge is to find out how to PARSE that character field into an XML tree.

Please look at posts in this forum that use the CREATE statement with the PARSE clause. Or, ask the team that is sending this XML why they are not doing as mqjeff and Vitor suggest.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Aug 04, 2016 6:05 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Please tell whoever is sending this message that they should rewrite how they are sending it, so it's a standard XML document and not anything with a CDATA section or worse an escaped string representing XML data.

You're going down the road to having a solution that breaks a lot... what if they suddenly decide to include characters in a different code page than the inside <xml> tag mentions?
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
smdavies99
PostPosted: Thu Aug 04, 2016 6:07 am    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

Vitor wrote:
[Why are you doing this?



The requirement is {perhaps?}

Sorry, if that is the case then whoever put the requirement together does not know XML and how to proprtly structure an XML document.

We see a lot of badly formed XML documents on this forum.
Collating these would make a good book on 'how not to format XML documents'.
_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Thu Aug 04, 2016 6:31 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

smdavies99 wrote:
We see a lot of badly formed XML documents on this forum.
Collating these would make a good book on 'how not to format XML documents'.

An excellent retirement activity!
_________________
chmod -R ugo-wx /
Back to top
View user's profile Send private message
sugan87
PostPosted: Thu Aug 04, 2016 6:32 am    Post subject: Reply with quote

Novice

Joined: 14 Jul 2016
Posts: 18

Thank to all, yours valuable comments,
I am able to parse that xml using CREATE statement with the PARSE clause.
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Aug 04, 2016 7:12 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

sugan87 wrote:
I am able to parse that xml using CREATE statement with the PARSE clause.


Congratulations on successfully implementing a really, really, stupid design.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
smdavies99
PostPosted: Thu Aug 04, 2016 8:42 am    Post subject: Reply with quote

Jedi Council

Joined: 10 Feb 2003
Posts: 6076
Location: Somewhere over the Rainbow this side of Never-never land.

mqjeff wrote:

An excellent retirement activity!


Retiring soon then Jeff?
_________________
WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995

Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » PARSE XML inside XML field
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.