Author |
Message
|
sugan87 |
Posted: Thu Aug 04, 2016 1:55 am Post subject: PARSE XML inside XML field |
|
|
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 |
|
 |
mqjeff |
Posted: Thu Aug 04, 2016 3:45 am Post subject: |
|
|
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 |
|
 |
timber |
Posted: Thu Aug 04, 2016 4:18 am Post subject: |
|
|
 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 |
|
 |
Vitor |
Posted: Thu Aug 04, 2016 4:43 am Post subject: Re: PARSE XML inside XML field |
|
|
 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 |
|
 |
mqjeff |
Posted: Thu Aug 04, 2016 4:47 am Post subject: |
|
|
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 |
|
 |
Vitor |
Posted: Thu Aug 04, 2016 4:54 am Post subject: |
|
|
 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 |
|
 |
sugan87 |
Posted: Thu Aug 04, 2016 5:36 am Post subject: |
|
|
Novice
Joined: 14 Jul 2016 Posts: 18
|
sorry masters, i have incorrectly posted the XML editor result.
The original XML is
<RootTextData>
<TextData><?xml version="1.0"?> <FormData> <FormContent><NamedInsured>Test1</NamedInsured> </FormContent> </FormData>
</TextData>
</RootTextData> |
|
Back to top |
|
 |
Vitor |
Posted: Thu Aug 04, 2016 5:54 am Post subject: |
|
|
 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 |
|
 |
timber |
Posted: Thu Aug 04, 2016 5:58 am Post subject: |
|
|
 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 |
|
 |
mqjeff |
Posted: Thu Aug 04, 2016 6:05 am Post subject: |
|
|
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 |
|
 |
smdavies99 |
Posted: Thu Aug 04, 2016 6:07 am Post subject: |
|
|
 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 |
|
 |
mqjeff |
Posted: Thu Aug 04, 2016 6:31 am Post subject: |
|
|
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 |
|
 |
sugan87 |
Posted: Thu Aug 04, 2016 6:32 am Post subject: |
|
|
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 |
|
 |
Vitor |
Posted: Thu Aug 04, 2016 7:12 am Post subject: |
|
|
 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 |
|
 |
smdavies99 |
Posted: Thu Aug 04, 2016 8:42 am Post subject: |
|
|
 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 |
|
 |
|