'Enable xinclude processing for Ants `schemavalidate` task
I'm using the schemavalidate
task of Ant to validate XML documents.
<schemavalidate
noNamespaceFile="${user.input.xsd}" file="${user.input.xml}">
</schemavalidate>
This works as expected. But now I have schema files using XInclude like this:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="..." xpointer="xmlns(xs=http://www.w3.org/2001/XMLSchema)xpointer(/xs:schema/xs:*)"/>
</xs:schema>
This gives the following error in Ant:
foo.xsd:8:136: s4s-elt-schema-ns: The namespace of element 'include' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'.
Now I tried enabling XInclude processing by enabling the corresponding feature:
<schemavalidate
noNamespaceFile="${user.input.xsd}" file="${user.input.xml}">
<attribute name="http://apache.org/xml/features/xinclude" value="true"/>
</schemavalidate>
But this doesn't help, the error message stays the same. The feature seems to be recognised by the parser, because when I change the attribute element to use some non-existing feature, I get a corresponding error message, e.g.
Parser org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser doesn't recognize feature http://apache.org/xml/features/xinclud
Is it possible to enable XInclude processing here?
Edit 1
When enabling Ant debug mode, I can see that the feature is set correctly:
[schemavalidate] Using SAX2 reader org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser
[schemavalidate] Setting feature http://xml.org/sax/features/validation=true
[schemavalidate] Setting feature http://apache.org/xml/features/xinclude=true
[schemavalidate] Setting feature http://xml.org/sax/features/namespaces=true
[schemavalidate] Setting feature http://apache.org/xml/features/validation/schema=true
[schemavalidate] Setting feature http://apache.org/xml/features/validation/schema-full-checking=true
[schemavalidate] Validating foo.xml...
Solution 1:[1]
Your schemavalidate task is correct. It seems to have been a bug in the past. I can say that it works with ant 1.10.9. Do not known when it was fixed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | renzo |