I'm trying to unmarshal an xml document that has the <xi:include>
tag inside it. But SAXParser doens't allow this even though I specificly tell the SAXParserFactory to allow it.
The 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 <xi:include>
tag from the XML document, the file is unmarshalled just fine. The unmarshaller has a schema attached to it. The schema doens't allow the <xi:include>
.
I used xmlns:xi="http://www.w3.org/2003/XInclude"
while I should have used xmlns:xi="http://www.w3.org/2001/XInclude"
Problem is fixed now!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With