I am trying to check the format of some XML files. The following code that I tried gives Premature end of file - fatal error. The following code content describes the String formed XML detail.
public static boolean formatXML (String content) throws SAXException, ParserConfigurationException, IOException
{
DocumentBuilderFactory factory = DocumentBuilderFactory .newInstance();
factory.setValidating(false);
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder;
builder.setErrorHandler(new SimpleErrorHandler());
builder.parse(new InputSource(new StringReader(content))); // Error comes here!
return true;
}
I am looking for the following questions but they were not helpful for me:
How can I solve this problem? I already checked the format of XML files with online checker and it is good formatted.
EDIT: content inside is really a XML detail. I checked by debugging. As I worked in Linux machine I could not copied my stacktrace but made a screenshot.