StAX parser with XPath
843834Aug 6 2009 — edited Nov 18 2009Hi,
I want to use the XPath to get the particular data from XML files.
The below code i've used to get the data.
DocumentBuilderFactory domFactory = DocumentBuilderFactory
.newInstance();
domFactory.setNamespaceAware(true);
DocumentBuilder builder = domFactory.newDocumentBuilder();
Document doc = builder.parse("persons.xml");
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression expr = xpath.compile("/information/person");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
It is using the DOM parser, but i want to use the StAX parser.
can you please suggest me how to use StAX parser with XPath?
Sunrays9