SAXParser 不允许 Xinclude

Era*_*tes 5 java xml sax xinclude

我正在尝试解组包含<xi:include>标签的 xml 文档。但是 SAXParser 不允许这样做,即使我特别告诉 SAXParserFactory 允许它。

Java代码:

SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setXIncludeaware(true);
spf.setNamespaceAwere(true);

spf.setFeature("http://apache.org/xml/features/xinclude", true);
spf.setFeature("http://apache.org/xml/features/xinclude/fixup-base-uris", true);

XMLReader xr = spf.newSAXParser().getXMLReader();
SAXSource source = new SAXSource(xr, new InputSource(inputStream));
JAXBElement<MyClass> el = unmarshaller.unmarshal(source, MyClass.class);
Run Code Online (Sandbox Code Playgroud)

要读取的 XML 文档

<?xml version="1.0" encoding="UTF-8"?>
<extension xmlns="http://www.example.com/test" xmlns:ext="http://www.example.com/test" xmlns:xi="http://www.w3.org/2003/XInclude">
    <visibility>
        <resourceConstraints>
            <resourceConstraint ext:resourceId="resourceOne">
                <role ext:show="true">AdminUsers</role>
            </resourceConstraint>
            <resourceConstraint ext:resourceId="resourceTwo">
                <role ext:show="true">AdminUsers</role>
            </resourceConstraint>
        </resourceConstraints>
        <xi:include href="extraContent.xml" />
    </visibility>
</extension>
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我得到这个异常:

org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 50; cvc-complex-type.2.4.a: Invalid content was found starting with element 'xi:include'. One of '{"http://www.example.com/test":resourceConstraints}' is expected.
Run Code Online (Sandbox Code Playgroud)

当我<xi:include>从 XML 文档中删除标记时,文件被解组就好了。解组器有一个附加到它的模式。架构不允许<xi:include>.

Era*_*tes 1

xmlns:xi="http://www.w3.org/2003/XInclude"应该使用的时候却使用了xmlns:xi="http://www.w3.org/2001/XInclude"

问题现已解决!