org.xml.sax.SAXParseException: Premature end of file
20,628
problem may exist in struts.xml file. The following line must be included in struts.xml file.
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
and <package>
tag must be written inside <struts>
tag inside sturts.xml file.
Related videos on Youtube
Comments
-
Cyril Deba almost 4 years
this is my xml file
<?xml version="1.0" encoding="utf-8"?> <settings></settings>
and my method is shown below
public void load( String fileName ) { ... Document xmlDocument = null; DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = null; try { builder = dbFactory.newDocumentBuilder(); xmlDocument = builder.parse(new File (fileName)); } catch( Exception e ) { Log.write(e); } ... }
When I invoke my method I receive the following:
[task] org.xml.sax.SAXParseException: Premature end of file. [task] at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249) [task] at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284) [task] at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:208) [task] at MyClass.load(MyClass.java:49)
I am completely confused.
Thanks for any ideas.
-Cyril
-
skaffman about 13 yearsCheck
File.exists()
beforebuilder.parse()
, just to make sure it is where you think it is. -
Ammu about 13 yearsI tried to run this code and it was working for me.
-
Kojotak about 13 yearsI has been thinking that this is an encoding issue (declared utf-8 xml file encoded as non utf-8), but my test didn't prove it.
-
-
Cyril Deba over 12 yearsproblem may exist with any xml file if the document is not well formated.
-
Cyril Deba almost 11 yearsNope, unfortunately there is nothing wrong about the content type