aspose file tools*
The moose likes XML and Related Technologies and the fly likes Retrieve CDTA content from XML file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Retrieve CDTA content from XML file" Watch "Retrieve CDTA content from XML file" New topic
Author

Retrieve CDTA content from XML file

Mirco H Schmidt
Greenhorn

Joined: Aug 25, 2010
Posts: 7

Hi,
I have a problem getting the CDATA section from my XML file:
<?xml version="1.0" encoding="UTF-8"?>
<ResultSet rows="37">
<Row index="0">
<Yanumber name="YANumber" type="varchar"><![CDATA[Y00042]]></Yanumber>
<Ybnumber name="YBNumber" type="varchar"><![CDATA[YB01329]]></Ybnumber>
</Row>
</ResultSet>


How can I retrieve in a loop all values from subelements Row in this case Yanumber and Ybnumber?
I tried using XPATH, JDOM
Document doc = new SAXBuilder().build("myxml.xml");
List<?> list = XPath.selectNodes(doc, "ResultSet/Row/Yanumber/text()");
for (Object object : list) {
if (object instanceof CDATA) {
CDATA output = (CDATA) object;
System.out.println(output.getValue());
}
}

... but this gave me only the Yanumber part.
How can I get all parts in a list ?

Thanks for your help
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12805
    
    5
That appears to be doing exactly what your xpath expression asked for:


Yanumber is what you specified.

If this was my problem I would get the Row Element, get a NodeList for all the child nodes, then iterate through the child nodes looking for Element nodes.

Note that all the children of Row will include Text type nodes as well as the Yanumber and Ybnumber Elements.

Bill
Mirco H Schmidt
Greenhorn

Joined: Aug 25, 2010
Posts: 7

thanks...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieve CDTA content from XML file