0

I want to be able to allow the following in my XSD but am stumped. I understand that I could use xs:any in a structure like this but this does not allow me define attributes for the elements that occur.

<xs:element name="parent">
  <xs:complexType>
    <xs:sequence>
      <xs:any minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

I would like to be able to have a defined parent and then have any element as a child but the children must have attributes specified by the following.

<xs:attribute name="attribute1" type="xs:string" use="required" />
<xs:attribute name="attribute2" type="xs:string"  />
<xs:attribute name="attribute3" type="xs:string" use="required" />

So I guess what I'm really asking is can I define the attributes for an any element? Below is the structure I want to acheive. Where the child elements of parent can take any name but must have the attributes as specified above. Thanks!

<parent>
    <AnyElementName1 attribute1="val1" attribute2="val2" attribute3="val3"/>
    <AnyElementName2 attribute1="val1" attribute2="val2" attribute3="val3"/>
    <AnyElementName3 attribute1="val1" attribute3="val3"/>
</parent>
Dan Smith
  • 280
  • 3
  • 13

1 Answers1

1

With xs:any you can constrain the namespace of the elements, and you use processContents="strict" to require that the element is one that's declared in the schema, but you can't constrain the elements to be of a particular type. Perhaps rather than using xs:any you should use xs:element naming an abstract element declaration, one whose type defines the required attributes, and then make all the permitted elements members of the substitution group of this abstract element.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164