SAXException Parser configuration problem: namespace reporting is not enabled

问题描述:

用sax的方式组装xml,在tomcat上正常运行,在weblogic12c上报错:

SAXException Parser configuration problem: namespace reporting is not enabled

JDK都是用的1.8

搜索,

发现SAXException Parser configuration problem: namespace reporting is not enabled来自 saxon jar包中的错误

找到代码:

// net.sf.saxon.event.ReceivingContentHandler

// It's also possible (especially when using a TransformerHandler) that the parser
        // has been configured to report the QName rather than the localname+URI
        if (localname.length() == 0) {
            throw new SAXException("Parser configuration problem: namespace reporting is not enabled");
        }

分析

通过

System.setProperty("javax.xml.transform.TransformerFactory",
                "net.sf.saxon.TransformerFactoryImpl");

即指定了SAXTransformerFactory的实现方式,便可以在单元测试时重现。

修复

在sax中做write时要指定localname,不能空着。

handler.startElement("", ROOT_ELEMENT_NAME, ROOT_ELEMENT_NAME, atts);

像这样即可修复。

原文地址:https://www.cnblogs.com/simoncook/p/7920882.html