This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XPath evaluate exception

 
Ramesh Patil
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am using the inputsource to evaluate xpaths from xml using Java's xerces xpath utility. Following is a snippet of the code.

InputStream stream = new ByteArrayInputStream(bytes);
InputSource inputSource = new InputSource();
inputSource.setByteStream(stream);
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
String val1 = (xpath.evaluate("/message/payload[1]/segment[1]/@encode", inputSource));

For multiple iterations of the above code and when running on debug, it throws this exception. It works fine while running the code without the debug. I think this has something to do with a connecton time out for the sax inputsource.

Fatal Error] :-1:-1: Premature end of file.
org.xml.sax.SAXParseException: Premature end of file.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:468)


Please help.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this has something to do with a connecton time out for the sax inputsource.


What connection? InputSource is based on local memory byte[] and is never going to time out.

I am guessing that for some reason bytes is an empty array and thus appears as an EOF.

Bill
 
Ramesh Patil
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more issue here is that every time I run the evaluate function, I need to get a new Input Source from the byte array.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to get a new Input Source from the byte array.


True! The JavaDocs for org.xml.sax.InputSource specifically state that the object is not reusable. However, the byte[] is not changed and creating a new InputSource should be computationally cheap.

So the question is what does "running on debug" have to do with it - what are you trying to do in the debug mode?

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic