1
votes

I've got a kml file(essentially xml) which has a set of nodes; name, description, coordinates etc. Up until now I have only been getting two values; name and coordinates. Now I want to get the description data as well, the only problem is that it is CData and when parsed it is ignored.

I've been using XQuery to get the data so far;

XPathExpression expr = xpath.compile("//name/text()");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for...

In the kml file its just <![CDATA[.....]>as opposed to "101" (an actual string) Using the same query it returns nothing.

The kml file has structure:

<Document>
  <Placemark>
    <name>101</name>
    <description><![CDATA[.....]]></description>
    <polygon>
      <coordinates>......</coordinates>
    </polygon>
  </Placemark>

  <Placemark>
  ....
  </Placemark>

</Document>    

Is there a way to do it through XQuery?

1
Post example of your KML - iTech
the kml structure is now included as well - user1892574
What XPath are you using to select the description? //description/text()? The information inside of the CDATA should be returned as text() content. - Mads Hansen
Yes thats what im using. Preferably yes, but id be happy with any data at the moment. - user1892574
Please make sure to post valid XML next time, there have been several syntax errors in it (closing tags without /, unclosed element, CDATA not properly closed). - Jens Erat

1 Answers

0
votes

Use the following XPath expression i.e. without specifying text():

XPathExpression expr = xpath.compile("//description");

and read the CDATA content with node.getTextContent()