I’m trying to read an xml file on from an android app using XOM as the XML library. I’m trying this:
Builder parser = new Builder();
Document doc = parser.build(context.openFileInput(XML_FILE_LOCATION));
But I’m getting nu.xom.ParsingException: Premature end of file. even when the file is empty.
I need to parse a very simple XML file, and I’m ready to use another library instead of XOM so let me know if there’s a better one. or just a solution to the problem using XOM.
In case it helps, I’m using xerces to get the parser.
——Edit—–
PS: The purpose of this wasn’t to parse an empty file, the file just happened to be empty on the first run which showed this error.
If you follow this post to the end, it seems that this has to do with
xercesand the fact that its an empty file, and they didn’t reach a solution onxercesside.So I handled the issue as follows:
And then I can do whatever I want with
doc. and you can add extra checks to make sure that the cause is really an empty file (like check the file size as indicated by one of sam’s comments on the question).