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!

XPATH evaluate method closing the input stream - Unable to reuse

843834May 11 2008 — edited Apr 30 2010
XPath xpath = XPathFactory.newInstance().newXPath();
String expressionYear = "/birthdate/year";
InputSource inputSource = new InputSource("myXMLDocument.xml");
NodeSet nodes = (NodeSet) xpath.evaluate(expressionYear, inputSource,
XpathConstants.NODESET);

String expressionMonth = "/birthdate/month";
NodeSet nodes = (NodeSet) xpath.evaluate(expressionMonth, inputSource, //Exception stream closed
XpathConstants.NODESET);

Where If we use Document object, it lets u re-use - Is this a bug or feature?

Document doc = ...
NodeSet nodes = (NodeSet) xpath.evaluate(expressionYear, doc,
XpathConstants.NODESET);

String expressionMonth = "/birthdate/month";
NodeSet nodes = (NodeSet) xpath.evaluate(expressionMonth, doc, //Exception stream closed
XpathConstants.NODESET);

Why is inconsistency ? I feel Programmer should be able to close "inputsource" when it is appropriate , evaluate method should not close.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 28 2010
Added on May 11 2008
10 comments
1,031 views