Announcement Announcement Module
Collapse
No announcement yet.
XPathOperations & RestClient multiple use question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    I'm suffering from exactly the same issue, did you ever find a solution to this? It would imagine that it must be an incredibly common use case to perform several XPath Operations on a single Source yet I can't find anything in the Spring documentation detailing whether this can be done.

    Comment


    • #3
      Unfortunately. We switched to JDOM and its XPath implementation in this case.

      Comment

      Working...
      X