SAXParser does not allow Xinclude

I am trying to unmount an XML document with a tag <xi:include>

inside it. But SAXParser doesn't allow it, even if I specifically tell SAXParserFactory to allow it.

Java code:

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);

      

XML document to read

<?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>

      

When I run it, I get this exception:

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.

      

When I remove the tag <xi:include>

from the XML document, the file renders fine. The non-marshaller has a schematic attached to it. This scheme does not allow <xi:include>

.

+3


source to share


1 answer


I used xmlns:xi="http://www.w3.org/2003/XInclude"

while I had to usexmlns:xi="http://www.w3.org/2001/XInclude"



The problem has now been fixed!

0


source







All Articles