• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XPath evaluate exception

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Y Patil
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic