469,646 Members | 1,596 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

XML Schema: How to put restrictions on element names

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

May 6 '06 #1
0 1115

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Kimmo J?rvikangas | last post: by
3 posts views Thread by Andrew Ducker | last post: by
1 post views Thread by shakuf | last post: by
2 posts views Thread by Shailendra Batham | last post: by
2 posts views Thread by Mike | last post: by
1 post views Thread by Robert Mago | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.