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

R

Robert Zurer

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
 
S

Stan Kitsis [MSFT]

<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"/>

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
R

Robert Zurer

<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

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top