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

Jim Croft jrc at ANBG.GOV.AU
Sun Feb 23 09:42:42 CET 2003


>How in XML-schema do you make sure that of two possible child
>elements, either or both, but not neither are present?

How about changing the model to 'choice' and requiring one but allowing two
(or multiple) occurrences of optional elements?

something like this maybe?

<?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 minOccurs="1" maxOccurs="2">
                                 <xs:element name="A" minOccurs="0"
maxOccurs="1"/>
                                 <xs:element name="B" minOccurs="0"
maxOccurs="1"/>
                         </xs:choice>
                 </xs:complexType>
         </xs:element>
</xs:schema>




~ Jim Croft ~ jrc at anbg.gov.au ~ 02-62465500 ~ www.anbg.gov.au/jrc/ ~




More information about the tdwg-content mailing list