Using xinclude and XMLSchema together

I'm trying to use xinclude to construct a schema which can then be parsed by XMLSchema. IOW, the following python script should print an XML document representing a valid XML schema and successfully create a XML schema object: --- include.py --- from lxml import etree tree = etree.parse("s1.xsd") tree.xinclude() print etree.tostring(tree) schema = etree.XMLSchema(tree) --- include.py --- Given the following two XML schema documents, this works as expected: --- s1.xsd --- <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xi="http://www.w3.org/2001/XInclude"> <xi:include href="s2.xsd" xpointer="/1/1"/> </xs:schema> --- s1.xsd --- --- s2.xsd --- <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="e1"> <xs:simpleType> <xs:restriction base="xs:boolean"/> </xs:simpleType> </xs:element> <xs:element name="e2"> <xs:simpleType> <xs:restriction base="xs:boolean"/> </xs:simpleType> </xs:element> </xs:schema> --- s2.xsd --- Executing the python script gives:
Now for the question: How do I include *every* element defined in s2 into s1? More precisely, I want the result of 'xpath -e '/xs:schema/*' s2.xsd' to be included into s1. I have experimented with various variations of the xpointer attribute to no avail. Any help would be greatly appreciated. TIA, Markus

This seems to work (for xinclude-ing all toplevel xs:elements: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xi="http://www.w3.org/2001/XInclude"> <xi:include href="s2.xsd" xpointer="xmlns (xs=http://www.w3.org/2001/XMLSchema)xpointer(/xs:schema/xs:element)"/> </xs:schema> Output: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xi="http://www.w3.org/2001/XInclude"> <xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema" name="e1"> <xs:simpleType> <xs:restriction base="xs:boolean"/> </xs:simpleType> </xs:element><xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema" name="e2"> <xs:simpleType> <xs:restriction base="xs:boolean"/> </xs:simpleType> </xs:element> </xs:schema> Or maybe /xs:schema/xs:* as the xpointer expression if you're not solely interested in elements. (I take it you really want to include schema elements verbatim because for XML Schema purposes you'd normally want to xs:include or xs:import schemas) Best regards, Holger Landesbank Baden-Wuerttemberg Anstalt des oeffentlichen Rechts Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz HRA 12704 Amtsgericht Stuttgart

Am 10.02.2016 um 13:36 schrieb Holger Joukl:
Perfect, thank you very much. This is in fact one of the many variations I tried, but I was missing the xmlns part in the xpointer expression.
Yes, I want to include them verbatim. The result of the inclusion is not only needed as an XML schema for validation purposes, but also as an XML document which is then processed further. Markus

This seems to work (for xinclude-ing all toplevel xs:elements: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xi="http://www.w3.org/2001/XInclude"> <xi:include href="s2.xsd" xpointer="xmlns (xs=http://www.w3.org/2001/XMLSchema)xpointer(/xs:schema/xs:element)"/> </xs:schema> Output: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xi="http://www.w3.org/2001/XInclude"> <xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema" name="e1"> <xs:simpleType> <xs:restriction base="xs:boolean"/> </xs:simpleType> </xs:element><xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema" name="e2"> <xs:simpleType> <xs:restriction base="xs:boolean"/> </xs:simpleType> </xs:element> </xs:schema> Or maybe /xs:schema/xs:* as the xpointer expression if you're not solely interested in elements. (I take it you really want to include schema elements verbatim because for XML Schema purposes you'd normally want to xs:include or xs:import schemas) Best regards, Holger Landesbank Baden-Wuerttemberg Anstalt des oeffentlichen Rechts Hauptsitze: Stuttgart, Karlsruhe, Mannheim, Mainz HRA 12704 Amtsgericht Stuttgart

Am 10.02.2016 um 13:36 schrieb Holger Joukl:
Perfect, thank you very much. This is in fact one of the many variations I tried, but I was missing the xmlns part in the xpointer expression.
Yes, I want to include them verbatim. The result of the inclusion is not only needed as an XML schema for validation purposes, but also as an XML document which is then processed further. Markus
participants (2)
-
Holger Joukl
-
Markus Schöpflin