Reputation: 69997
How can I set an xsd:element type to be the XMLSchema (which defines the structure of XSD files)? Is it even possible?
For example, I need a XML file which lists multiple XSDs under its root element:
<schemas xmlns:xs=''>
<xs:schema...>
<xs:element name='...'/>
</xs:schema>
<xs:schema...>
</xs:schema>
</schemas>
The schema of this XML would look like this:
<xs:schema xmlns:xs=''>
<xs:element name='schemas'>
<xs:complexType>
<xs:sequence>
<xs:element name='schema' type='xs:schema'
minoccurs='0' maxoccurs='unbounded'/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Of course, there is no such type as xs:schema
. How can I make this work?
Upvotes: 0
Views: 438
Reputation: 2531
Yes, it is quite possible. Here's how:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!--
Any XML schema processor does know XML schema language,
but it is not supposed to know an XML schema for it.
You need to import it!
-->
<xs:import namespace="http://www.w3.org/2001/XMLSchema"
schemaLocation="http://www.w3.org/2001/XMLSchema.xsd"/>
<xs:element name="schemas">
<xs:complexType>
<xs:sequence>
<!--
You don't need an 'xs:schema' type. Rather you just need
to reference an already existing 'xs:schema' element
-->
<xs:element minoccurs="0" maxoccurs="unbounded" ref="xs:schema"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
You may look also in the XML schema for XSLT:
http://www.w3.org/2007/schema-for-xslt20.xsd.
They do the same in the definition of <xsl:import-schema>
element.
Upvotes: 3