Expecting End of File Exception in parsing xml dat

2019-12-16 20:30发布

问题:

I am getting parser exception as "Expecting End of File" while parsing xml data for Blackberry application?

How do I fix it?

回答1:

I encountered the the same org.xml.sax.SAXException while developing a child class of org.xml.sax.helpers.DefaultHandler for processing an XML file on Blackberry.

The issue in my case was that my sample XML file was not well-formed. Specifically, there was not only one root element in the XML file. My broken XML file had several root-level tags, and SAX was complaining that it found a second one. The file looked something like this:

<?xml version="1.0"?>
<number>one</number>
<number>two</number>
<number>three</number>

To fix it, I just encapsulated those items into one root element named "counting":

<?xml version="1.0"?>
<counting>
<number>one</number>
<number>two</number>
<number>three</number>
</counting>

You can see a few of the XML rules on Wikipedia here.