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

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

From: Tom Elrod <telrod@e2technologies.net>
Date: Wed, 6 Jun 2001 15:10:02 -0400 (EDT)
Message-ID: <3B1E7FF6.C2E959D1@e2technologies.net>
To: xmlschema-dev@w3.org
I am pretty new to XML Schemas, so sorry if this is a dumb question, but
couldn't find doc on it anywhere.

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.


<?xml version="1.0" encoding="UTF-8"?>
<MailingDefinition
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="C:\Projects\xml\msgdef.xsd">
 <Header>
  <Subject>this is a mailing example</Subject>
  <MailingName>this is the name of the mailing</MailingName>
  <FromName>Tom Elrod</FromName>
  <FromAddress>telrod@yahoo.com</FromAddress>
   <ReplyTo>telrod@yahoo.com</ReplyTo>
  <SendDate>2001-12-31</SendDate>
  <!-- Can sufix with a time zone indicator. For example, to indicate
1:20 pm for Eastern Standard Time which is 5 hours behind Coordinated
Universal Time (UTC), one would write: 13:20:00-05:00 -->
  <SendTime>13:20:00</SendTime>
  <!-- Mailing ID is optional.  If not present, then will be generated.
Otherwise, use one specified -->
  <MailingID>1001</MailingID>
  <!-- Should either have a Recipient element or ListID element -->
  <!-- <ListID>3221</ListID>-->
  <Recipients>
   <Recipient>
    <!-- email element is required -->
    <email>telrod@e2technologies.net</email>
    <FirstName>Tom</FirstName>
    <LastName>Elrod</LastName>
    <Salutation>Hello</Salutation>
   </Recipient>
   <Recipient>
    <email>telrod@yahoo.com</email>
    <FirstName>Thomas</FirstName>
    <LastName>Elrod</LastName>
    <Salutation>Whatzup</Salutation>
   </Recipient>
  </Recipients>
  </Header>
</MailingDefinition>


<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
elementFormDefault="qualified">
 <xsd:element name="MailingDefinition">
  <xsd:complexType>
   <xsd:sequence>
    <xsd:element name="Header">
     <xsd:complexType>
      <xsd:sequence>
       <xsd:element name="Subject" type="xsd:string"/>
       <xsd:element name="MailingName" type="xsd:string"/>
       <xsd:element name="FromName" type="xsd:string"/>
       <xsd:element name="FromAddress" type="xsd:string"/>
       <xsd:element name="ReplyTo" type="xsd:string"/>
       <xsd:element name="SendDate" type="xsd:date">
        <xsd:annotation>
         <xsd:documentation>Can sufix with a time zone indicator. For
example, to indicate 1:20 pm for Eastern Standard Time which is 5 hours
behind Coordinated Universal Time (UTC), one would write:
13:20:00-05:00</xsd:documentation>
        </xsd:annotation>
       </xsd:element>
       <xsd:element name="SendTime" type="xsd:time"/>
       <xsd:element name="MailingID" type="xsd:string" minOccurs="0">
        <xsd:annotation>
         <xsd:documentation>If not provided, will be generated by Mail
Manager when creating new mailing</xsd:documentation>
        </xsd:annotation>
       </xsd:element>
       <xsd:choice>
        <xsd:element name="ListID" type="xsd:string"/>
        <xsd:element name="Recipients">
         <xsd:complexType>
          <xsd:all>
           <xsd:element name="Recipient" maxOccurs="unbounded">
            <xsd:complexType>
             <xsd:all>
              <xsd:element name="email" type="xsd:string"/>
             </xsd:all>
            </xsd:complexType>
           </xsd:element>
          </xsd:all>
         </xsd:complexType>
        </xsd:element>
       </xsd:choice>
      </xsd:sequence>
     </xsd:complexType>
    </xsd:element>
   </xsd:sequence>
  </xsd:complexType>
 </xsd:element>
</xsd:schema>


Thanks.

-Tom
Received on Monday, 11 June 2001 05:37:20 GMT

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