Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

StAX parser with XPath

843834Aug 6 2009 — edited Nov 18 2009
Hi,

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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 16 2009
Added on Aug 6 2009
3 comments
1,381 views