Results 1 to 3 of 3

Thread: XPathOperations & RestClient multiple use question

  1. #1
    Join Date
    Jan 2010
    Posts
    15

    Default 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. #2
    Join Date
    May 2009
    Posts
    12

    Default

    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.

  3. #3
    Join Date
    Jan 2010
    Posts
    15

    Default

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •