W3C home > Mailing lists > Public > xmlschema-dev@w3.org > June 2001

Re: Allowing any sub-element while requiring one particular sub-element

From: Eddie Robertsson <eddie@allette.com.au>
Date: Thu, 14 Jun 2001 09:52:45 +1000
Message-ID: <3B27FCCD.62269B5A@allette.com.au>
To: Tom Elrod <telrod@e2technologies.net>
CC: xmlschema-dev@w3.org
Hi Tom,

> I am building an XML Schema and I would like one of the elements to
> allow any sub-elements of any type (I won't know what they are) and
> require that there is one particular sub-element.  The schema and sample
> XML is included below.  The element 'Recipient' is the one that I want
> to allow any number of sub elements (such as 'FirstName'), but require
> the 'email' element be there.

Have you tried using xsd:any?
xsd:any let you have any Well-Formed XML and you can specify if you want the
processor to validate the content and from which namespace the elements can
be declared in. Have a look at [1] for more details.

In your schema you could declare your element Recipient like:

<xsd:element name="Recipient">
   <xsd:complexType>
      <xsd:sequence>
         <xsd:element name="email" type="xsd:string"/>
         <xsd:any processContents="skip" namespace="##any" minOccurs="0"
maxOccurs="unbounded"/>
      </xsd:sequence>
   </xsd:complexType>
</xsd:element>

Cheers,
/Eddie

[1] http://www.w3.org/TR/xmlschema-0/#any
Received on Wednesday, 13 June 2001 19:52:00 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:21 GMT