aspose file tools*
The moose likes XML and Related Technologies and the fly likes XPath evaluate exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XPath evaluate exception" Watch "XPath evaluate exception" New topic
Author

XPath evaluate exception

Ramesh Patil
Greenhorn

Joined: Aug 09, 2004
Posts: 17
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

Joined: Mar 22, 2000
Posts: 12835
    
    5
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

Joined: Aug 09, 2004
Posts: 17
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

Joined: Mar 22, 2000
Posts: 12835
    
    5
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
 
subject: XPath evaluate exception