首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >比较XML文件时出现XMLUNIT命名空间异常

比较XML文件时出现XMLUNIT命名空间异常
EN

Stack Overflow用户
提问于 2016-07-12 13:09:43
回答 1查看 435关注 0票数 0

我有两个XML文件,当使用XMLUNIT比较它们时,我得到了下面的异常。

代码语言:javascript
复制
Exception in thread "main" org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
    at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.checkDOMNSErr(CoreDocumentImpl.java:2530)
    at com.sun.org.apache.xerces.internal.dom.AttrNSImpl.setName(AttrNSImpl.java:117)
    at com.sun.org.apache.xerces.internal.dom.AttrNSImpl.<init>(AttrNSImpl.java:78)
    at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.createAttributeNS(CoreDocumentImpl.java:2142)
    at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1596)
    at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1560)
    at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.cloneNode(CoreDocumentImpl.java:362)
    at com.sun.org.apache.xerces.internal.dom.DocumentImpl.cloneNode(DocumentImpl.java:159)
    at org.custommonkey.xmlunit.XMLUnit.stripWhiteSpaceWithoutXSLT(XMLUnit.java:522)
    at org.custommonkey.xmlunit.XMLUnit.getWhitespaceStrippedDocument(XMLUnit.java:506)
    at org.custommonkey.xmlunit.Diff.getWhitespaceManipulatedDocument(Diff.java:182)
    at org.custommonkey.xmlunit.Diff.getManipulatedDocument(Diff.java:203)
    at org.custommonkey.xmlunit.Diff.<init>(Diff.java:155)
    at org.custommonkey.xmlunit.Diff.<init>(Diff.java:168)
    at org.custommonkey.xmlunit.DetailedDiff.<init>(DetailedDiff.java:60)

我正在使用下面的代码,它不能像预期的那样工作。

代码语言:javascript
复制
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    factory.setValidating(false);

    try {
        factory.setFeature("http://xml.org/sax/features/namespaces", false);
        factory.setFeature("http://xml.org/sax/features/validation", false);
        factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
        factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);;
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }

    XMLUnit.setTestDocumentBuilderFactory(factory);
    XMLUnit.setControlDocumentBuilderFactory(factory);
    XMLUnit.setIgnoreWhitespace(Boolean.TRUE);
    XMLUnit.setIgnoreComments(true);
    XMLUnit.setIgnoreAttributeOrder(true);

如何让XMLUNIT忽略名称空间验证?

EN

回答 1

Stack Overflow用户

发布于 2016-07-12 15:12:57

删除下面的2行代码使我的代码可以正常工作。

代码语言:javascript
复制
factory.setFeature("http://xml.org/sax/features/namespaces", false);
factory.setFeature("http://xml.org/sax/features/validation", false);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38320452

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档