|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Parsing XML message having CDATA section using XMLNSC parser |
« View previous topic :: View next topic » |
Author |
Message
|
DrajMQ |
Posted: Wed Sep 03, 2014 9:52 pm Post subject: Parsing XML message having CDATA section using XMLNSC parser |
|
|
Newbie
Joined: 29 Mar 2014 Posts: 7
|
Hi All,
I have a XML message which has a CDATA section in it. I am using XMLNSC parser to parse it.
If my XML message is as below -
<?xml version="1.0"?>
<!DOCTYPE body [
<!ELEMENT body (#PCDATA)>]>
<body><![CDATA[
Here is an example of an internal DTD:
<!DOCTYPE lab_group [
<!ELEMENT lab_group (student_name)*>
<!ELEMENT student_name (#PCDATA)>
<!ATTLIST student_name student_no ID #REQUIRED>
<!ATTLIST student_name tutor_1 IDREF #IMPLIED>
<!ATTLIST student_name tutor_2 IDREF #IMPLIED>
]>
]]></body>
This is parsed as the body element as simple element with field name as "body" and its value as the <CDATA string>.
But if my XML message is as below -
<?xml version="1.0"?>
<!DOCTYPE body [
<!ELEMENT body (#PCDATA)>]>
<body>
<![CDATA[
Here is an example of an internal DTD:
<!DOCTYPE lab_group [
<!ELEMENT lab_group (student_name)*>
<!ELEMENT student_name (#PCDATA)>
<!ATTLIST student_name student_no ID #REQUIRED>
<!ATTLIST student_name tutor_1 IDREF #IMPLIED>
<!ATTLIST student_name tutor_2 IDREF #IMPLIED>
]>
]]></body>
Note the newline after <body> tag, the message is parsed as body being a compex element and some child elements created for it one of which has new lines as its value and the second child with the CDATA value.
After going through below link -
http://www-01.ibm.com/support/knowledgecenter/#!/SSMKHH_9.0.0/com.ibm.etools.mft.doc/ac67195_.htm
I guess above is the expected behaviour for XMLNSC parser.
But I have one requirement to treat both the above XML messages same. Is there any way to achieve this to make the XML message (with new line characters) similar to the first XML message? _________________ Thank,
Dhiraj Khot |
|
Back to top |
|
 |
kash3338 |
Posted: Wed Sep 03, 2014 10:34 pm Post subject: |
|
|
Shaman
Joined: 08 Feb 2009 Posts: 709 Location: Chennai, India
|
One option is to use REPLACE statement to replace the <CR><LF> (whose Hex values are '0D', '0A') to trim off the new lines from your string. |
|
Back to top |
|
 |
kimbert |
Posted: Wed Sep 03, 2014 11:22 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
@kash338 : No, that is *not* the best solution. There is a much cleaner solution.
@DrajMQ: You are looking at this from the wrong perspective. XMLNSC is doing exactly what any other XML parser would do - try it with Java/Xercesand see what shape of DOM tree you obtain.
When working with a DOM node that has multiple child text nodes the programmer does not need to access the individual nodes. The textContent() method (http://www.w3schools.com/dom/prop_node_textcontent.asp) returns the text value of all child nodes. When working with XMLNSC, the FIELDVALUE function performs the same trick - it returns the text value of all child nodes concatenated together. _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
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
|
|
|
|