XSD: How to allow an element withjany name but require it to have certain attributes

Robert Zurer

Usenet Archive
Joined
Mar 28, 2002
Messages
26
Reaction score
0
I want to create a schema element that will allow any element as a child but that child must contain specified attributes

This example doesn't work but it might give an idea of what I need to do.

<xs:element name="???">
<xs:complexType>
<xs:attribute name="attrOne" type="xs:string" use="required" /> <xs:attribute name"attrTwo" type="xs:string" use="required" /> </xs:complexType> </xs:element>

<xs:element name="parent_element">
<xs:complexType>
<xs:sequence>
<xs:element ref="???" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element>

This file should be valid

<parent_element>
<hello attrOne="world" attrTwo="planet"/>
<kitty attrOne="cat" attrTwo="feline"/>
</parent_element>

This file should be invalid

<parent_element>
<hello/>
<kitty/>
</parent_element>

I can accomplish the any child element part

<xs:element name="parent_element">
<xs:complexType>
<xs:sequence>
<xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element>

But this will not force the elements to have the attributes I need.

Robert Zurer
 

Stan Kitsis MSFT

Usenet Archive
Joined
Dec 15, 2004
Messages
64
Reaction score
0
<xs:complexType name="anyPlusAttrsType">
<xs:sequence>
<xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute name="att1" type="xs:string" use="required"/> <xs:attribute name="att2" type="xs:string" use="required"/> </xs:complexType> <xs:element name="foo" type="anyPlusAttrsType"/>
 

Robert Zurer

Usenet Archive
Joined
Mar 28, 2002
Messages
26
Reaction score
0
<xs:complexType name="anyPlusAttrsType">
<xs:sequence>
<xs:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute name="att1" type="xs:string" use="required"/> <xs:attribute name="att2" type="xs:string" use="required"/> </xs:complexType> <xs:element name="foo" type="anyPlusAttrsType"/>
It's obvious that I need to do some more reading on the basics.

Thanks so much for your response.

Robert Zurer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,051
Messages
3,104,251
Members
248,135
Latest member
tobystanx

Latest Threads

Top