How to solve docbuiler saxexception: unexpected end of document?

Posted by user211992 on Stack Overflow See other posts from Stack Overflow or by user211992
Published on 2010-03-15T10:24:00Z Indexed on 2010/03/15 10:29 UTC
Read the original article Hit count: 277

Filed under:
|

I have a service that gives some car information in an xml format.

<?xml version="1.0" encoding='UTF-8'?>
<car>
   <id>5</id>
   <name>qwer</name>
</car>
<car>
   <id>6</id>
   <name>qwert</name>
</car>

Now the problem that I'm having is that my

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(xml);

Sometimes throws a SAXException (sometimes it works just fine, but when I reboot the server (still in development) I sometimes keep getting it) with as cause SAXException: unexpected end of document.

But when I place a bufferreader there to see what it's receiving and I copy the value into an xml document and I open it in firefox/ie it looks just fine.

© Stack Overflow or respective owner

Related posts about java

Related posts about Xml