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.

Share:
20,628

Related videos on Youtube

Cyril Deba
Author by

Cyril Deba

a software development practitioner.

Updated on July 06, 2020

Comments

  • Cyril Deba
    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
      skaffman about 13 years
      Check File.exists() before builder.parse(), just to make sure it is where you think it is.
    • Ammu
      Ammu about 13 years
      I tried to run this code and it was working for me.
    • Kojotak
      Kojotak about 13 years
      I 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
    Cyril Deba over 12 years
    problem may exist with any xml file if the document is not well formated.
  • Cyril Deba
    Cyril Deba almost 11 years
    Nope, unfortunately there is nothing wrong about the content type