如何解决SXXP0003:XML解析器报告错误:文件过早结束

时间:2019-02-02 17:46:55

标签: java

我收到错误解析时使用XSLT我的XML:

11439.xml的第1行第1列错误:

SXXP0003: Error reported by XML parser: Premature end of file.
net.sf.saxon.trans.XPathException: org.xml.sax.SAXParseException; systemId: file:/C:/Users/rimancha/Desktop/SaveDir/11439/11439.xml; lineNumber: 1; columnNumber: 1; Premature end of file.
    at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:418)
    at net.sf.saxon.event.Sender.send(Sender.java:214)
    at net.sf.saxon.event.Sender.send(Sender.java:50)

我的代码是:

public class XsltFolderWise {
    public static void main(String[] args) {
        File curDir = new File("C:/Users/rimancha/Desktop/SaveDir/11439"); // current  directory

        displayDirectoryContents(curDir);
    }

    public static void displayDirectoryContents(File dir) {
        try {
            File[] files = dir.listFiles();
            for (File file : files) {
                if (file.isDirectory()) {
                //  System.out.println("directory:" + file.getCanonicalPath());
                    displayDirectoryContents(file);

                } else {
                    System.out.println("file:" + file.getCanonicalPath());
                    String XSLFILE = "C:/Users/rimancha/Desktop/SaveDir/jars/command-reference.xsl";
                    File INFILE = file;
                    String OUTFILE = "C:/Users/rimancha/Desktop/SaveDir/output_xslt/output"
                            + file;
                    StreamSource xslCode = new StreamSource(new File(XSLFILE));
                    StreamSource input = new StreamSource((INFILE));
                    File out=new File(OUTFILE);
                    if (!out.exists()) {
                        System.out.println(OUTFILE
                                + " created successfully? "
                                + out.mkdirs());
                    }
                    StreamResult output = new StreamResult(out);

                    //TransformerFactory tf = TransformerFactory.newInstance();
                    TransformerFactory tf = TransformerFactory.newInstance(
                            "net.sf.saxon.TransformerFactoryImpl", null);

                    Transformer trans = tf.newTransformer(xslCode);
                    trans.setOutputProperty(OutputKeys.INDENT, "yes");
                    trans.setOutputProperty(
                            "{http://xml.apache.org/xslt}indent-amount", "4");

                    try {
                        trans.transform(input, output);
                    } catch (TransformerException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TransformerConfigurationException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
}

无法解决问题。任何人都遇到这个问题,或者有这方面的解决方案?是我的XSLT有一些问题,或者什么else.Please帮帮我!

0 个答案:

没有答案