Cyril Deba
Cyril Deba

Reputation: 1210

org.xml.sax.SAXParseException: Premature end of file

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

Upvotes: 2

Views: 21988

Answers (2)

Qstacker
Qstacker

Reputation: 255

Make sure the content type content-type:text/xml; charset=utf-8

Upvotes: 0

anamika
anamika

Reputation: 21

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.

Upvotes: 2

Related Questions