Parsing an XML string for a list of items
String myString = "" 4 3
final DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
document = docBuilder.parse(new InputSource(new StringReader(myString)));
document.getDocumentElement().normalize();
final XPath xpath = XPathFactory.newInstance(),newXPath()
final NodeList sections = (NodeList) xpath.evaluate("/SurfaceIds/SurfaceId", document, XPathConstants.NODESET);
if (sections != null) { //alway check for null here
for (int i=0; i< sections.getLength(); i++) {
Node node = sections.item(i);
String idString = node.getTextContent();
....
...
}
}
0 Comments:
Post a Comment
<< Home