I think it’s a problem with your xml file. The error translated is: The file ended early! The xml file may have no end tag, wrong start tag, etc. You may encounter this error! Please post your complete xml file
Problem: Input stream is opened and read bytes from it, passed the same to document builder to parse method. so it caused the exception saying premature end of file.
Solution: Pass fresh input stream which is opened and not read anything (bytes) before passing to parse method of DocumentBuilder object.
I tried it with your code and no errors occurred. If there is an error with dom4j, try something else
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
ClassPathResource resource = new ClassPathResource("reportType.xml");
Document doc = builder.parse(resource.getInputStream());
Element root = doc.getDocumentElement();
NodeList list = root.getChildNodes();
for (int i = 0, len = list.getLength(); i < len; i++) {
}
I think it’s a problem with your xml file. The error translated is: The file ended early! The xml file may have no end tag, wrong start tag, etc. You may encounter this error! Please post your complete xml file
Encoding problem? Try changing the xml file attributes to UTF-8