XML: How to require either or both of two child elements, but prevent both missing?

Pavel Benda pavelben at SENDME.CZ
Sun Feb 23 11:49:26 CET 2003


Hi all,

I suppose William Ullate is right way; nevertheless, his example isn't
completed and doesn't work.

The correct syntax of William code is here:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">

 <xs:element name="Parent">
  <xs:complexType>
   <xs:choice>
    <xs:group ref="elementAoptB"/>
    <xs:element ref="elementB" minOccurs="1"/>
   </xs:choice>
  </xs:complexType>
 </xs:element>
 <xs:group name="elementAoptB">
  <xs:sequence>
   <xs:element name="elementA" minOccurs="1"/>
   <xs:element ref="elementB" minOccurs="0"/>
  </xs:sequence>
 </xs:group>

 <xs:element name="elementB"/>
</xs:schema>

This work fine.

Pavel Benda
Czech Collection of Microorganisms
pavelben at sendme.cz




More information about the tdwg-content mailing list