I have created XML Schema for an XML document that describes functionality of components of a complex modular system. Within that XML document, I want to include XML Schema which will be read and parsed to allow for configuration.
meta-schema.xsd
(heavily edited for brevity):
<xs:schema targetNamespace="urn:project"
xmlns="urn:project"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="Schema" type="SchemaType"/>
<xs:complexType name="SchemaType">
<xs:sequence>
<xs:element type="ConfigurationType" name="Configuration"/>
<xs:any maxOccurs="unbounded" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ConfigurationType">
<xs:sequence>
<xs:element ref="xs:schema"/> <!-- Does not work -->
</xs:sequence>
<xs:anyAttribute/>
</xs:complexType>
</xs:schema>
The desired XML (written by folks developing modules):
<Schema xmlns="urn:project"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:project meta-schema.xsd">
<!-- Snip -->
<Configuration>
<schema>
<element name="enable" type="boolean">
<annotation>
<appinfo>Usage:</appinfo>
<documentation xml:lang="en">
Enable functionality
</documentation>
</annotation>
</element>
</schema>
</Configuration>
</Schema>
Is this possible to express in XSD? If so, how?
Edit:
Based on kjhughes's comment, this is not possible. My solution was to use an any
element with an ##other
namespace, with a comment:
<xs:complexType name="ConfigurationType">
<xs:choice>
<xs:element name="hex" type="xs:hexBinary"/>
<xs:element name="base64" type="xs:base64Binary"/>
<!-- If configuration isn't binary, modules should create an XML Schema of the configuration options in order to
facilitate future tooling, when feasible. -->
<xs:any namespace="##other" processContents="lax"/>
</xs:choice>
<xs:anyAttribute/>
</xs:complexType>
Which enables the following XML:
<Schema xmlns="urn:project"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:project meta-schema.xsd">
<!-- Snip -->
<Configuration>
<xs:schema targetNamespace="urn:project"
xmlns="urn:project"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
<xs:element name="enable" type="xs:boolean">
<xs:annotation>
<xs:appinfo>Usage:</xs:appinfo>
<xs:documentation xml:lang="en">
Enable left radial pulse functionality
</xs:documentation>
</xs:annotation>
</xs:element>
</xs:schema>
</Configuration>
</Schema>