The processing instruction target matching "[xX][mM][lL]" is not allowed.

通过dom4j读取xml文件内容,总是出现如下错误:

The processing instruction target matching "[xX][mM][lL]" is not allowed. Nested exception: The proc.... 

经过全面排查,发现xml标签都正常,最后使用xml校验工具,发现某些节点尾部带有"空格",将其去掉后,程序运行正常。

        SAXReader reader = new SAXReader();
        Document document;
        String rootXmlText = null;
        try {
            String path = System.getProperty("user.dir");
            StringBuffer sb = new StringBuffer().append(path).append(
                    FILE_SEPARAOR).append(jkid).append(XML_EXTENSION);
            File file = new File(sb.toString());
            if (!file.exists()) {
                return null;
            }
            document = reader.read(file);  //此处始终报上述错误
原文地址:https://www.cnblogs.com/hutton/p/3766952.html