Hi there,
I want to set up an XML Schema for documents of the following structure:
The <root> node contains
- an optional <message> element with a text attribute, and
- arbitrary further content.
To make the parts unique, the top-level element of the further content must not have the name "message". Therefore, this further content is not completely arbitrary, but there is a restriction on the element name.
Examples:
<root>
<message text="Hi there"/>
<purchaseOrder number="4711">
<item number="10" matnr="4033871" qty="10"/>
</purchseOrder>
</root>
<root>
<message text="Only message"/>
</root>
<root>
<!-- only further content -->
<part number="10">
<option key="10" text="First option"/>
<option key="20" text="Second option"/>
</part>
</root>
In an imagined, non-existing XML Schema syntax, the further content should be defined somehow like
<xs:restriction refType="xs:any">
<xs:condition test="local-name!='message'"/>
</xs:restriction>
Since I don't know how to do such a thing in the existing XML-Schema language, I tried to use <xs:any> without restrictions. But this didn't pass the XSD Validator, due to the non-uniqueness of a possible message element:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="root"> <xs:complexType> <xs:sequence> <xs:element name="message" minOccurs="0" maxOccurs="1"> <xs:complexType> <!-- leaving out attribute definitions for simplicity... --> </xs:complexType> </xs:element> <xs:any minOccurs="0" processContents="skip"/> <!-- ^^^^^ For this part, we need a restriction on the element name!!! --> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
Any suggestion how to define arbitrary elements
with restricted element name in XML Schema???
Thanks
Ruediger
I want to set up an XML Schema for documents of the following structure:
The <root> node contains
- an optional <message> element with a text attribute, and
- arbitrary further content.
To make the parts unique, the top-level element of the further content must not have the name "message". Therefore, this further content is not completely arbitrary, but there is a restriction on the element name.
Examples:
<root>
<message text="Hi there"/>
<purchaseOrder number="4711">
<item number="10" matnr="4033871" qty="10"/>
</purchseOrder>
</root>
<root>
<message text="Only message"/>
</root>
<root>
<!-- only further content -->
<part number="10">
<option key="10" text="First option"/>
<option key="20" text="Second option"/>
</part>
</root>
In an imagined, non-existing XML Schema syntax, the further content should be defined somehow like
<xs:restriction refType="xs:any">
<xs:condition test="local-name!='message'"/>
</xs:restriction>
Since I don't know how to do such a thing in the existing XML-Schema language, I tried to use <xs:any> without restrictions. But this didn't pass the XSD Validator, due to the non-uniqueness of a possible message element:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="root"> <xs:complexType> <xs:sequence> <xs:element name="message" minOccurs="0" maxOccurs="1"> <xs:complexType> <!-- leaving out attribute definitions for simplicity... --> </xs:complexType> </xs:element> <xs:any minOccurs="0" processContents="skip"/> <!-- ^^^^^ For this part, we need a restriction on the element name!!! --> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
Any suggestion how to define arbitrary elements
with restricted element name in XML Schema???
Thanks
Ruediger