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 » Parsing XML message having CDATA section using XMLNSC parser

Post new topic  Reply to topic
 Parsing XML message having CDATA section using XMLNSC parser « View previous topic :: View next topic » 
Author Message
DrajMQ
PostPosted: Wed Sep 03, 2014 9:52 pm    Post subject: Parsing XML message having CDATA section using XMLNSC parser Reply with quote

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
View user's profile Send private message
kash3338
PostPosted: Wed Sep 03, 2014 10:34 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
kimbert
PostPosted: Wed Sep 03, 2014 11:22 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Parsing XML message having CDATA section using XMLNSC parser
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.