CDATA problem

B

bestia9

Hello,

I need a little help. I want to read the CDATA from an XML file :


....
<EpgDescription>

<![CDATA[ Matrix]]>

</EpgDescription>
....

I use this code to read the CDATA:

Node EpgDescription =
XPathAPI.selectSingleNode(ScheduleNodeListNode,"EpgDescription");

Node firstchild = EpgDescription.getFirstChild();

System.out.println("start
:"+firstchild.getNodeName()+"-"+firstchild.getNodeValue()+" :end");

The problem is when i Print my node name and my node value on the
screen. I see this:

start :#text-
:end


How can I print Matrix?

Thx
 
J

Johannes Koch

<EpgDescription>

<![CDATA[ Matrix]]>

</EpgDescription> [...]
System.out.println("start
:"+firstchild.getNodeName()+"-"+firstchild.getNodeValue()+" :end");

The problem is when i Print my node name and my node value on the
screen. I see this:

start :#text-
:end

The CDATA section is not the first child node of the EpgDescription
element. It's text node with white space. Try looping over all child
nodes and concatenate the values.
 
J

JAPISoft

Hello,

Your code is correct but the problem is in your document structure, if
you don't have a DTD or a Schema W3C, your blank text will be considered
as text node too so your first child node is not the CDATA part but the
previous blank part.

Best wishes,

A.Brillant
EditiX - XML Editor and XSLT Debugger
http://www.editix.com
 
B

bestia9

Thx guy's

Problem is solved by loping all the childnodes i found the problem.
there are 3 childnode's
The first and last node are null.
the second contains the Matrix

THX

Regards

Marco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top