XPathOperations & RestClient multiple use question
Hi!
This is a bit test-case: I have an immutable object which should contain some String properties obtained by XPath. Factory method is:
Code:
public static ImmutableObject parseSource(Source src, XPathOperations xpathOperator) {
String property1 = xpathOperator.evaluateAsString("/root/foo/bar/interestingTag", src);
String property2 = xpathOperator.evaluateAsString("/root/anotherInterestingTag", src);
return new ImmutableObject(property1, property2);
}
The argument "src" is obtained from RestTemplate:
Code:
Source someSrc = restClient.getForObject("http://myserver/example.xml", Source.class);
If you execute such code you will probably run into: "SAXException: Premature end of file" (which occurs in the second evaluateAsString calling).
The reason is quite simple (although it was hard for me to figure it out, even with Google), Source's InputSource is "consumed" by the first calling, therefore it's closed when the next calling executes = premature EOF. [http://www.danielschneller.com/2008/...re-end-of.html]
My question is simple, what should I do? My XML schema are quite complicated and I need only a few informations; XPath seems as the best choice (for the moment). However I need somehow to clone my Source's InputSource objects (despite the fact it is not possible).
Zdenek