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

Guillaume Rousse rousse at CCR.JUSSIEU.FR
Sun Feb 23 12:55:50 CET 2003


Le Dimanche 23 Février 2003 09:26, vous avez écrit :
> Wouldn't this example too would allow for 2 B's?  It may be messy
> (especially if you progress beyond two elements), but couldn't you just use
> a choice allowing for only one of an A-B group, an A or a B?
That was also my idea (see attached files), however it is prohibited for 
ambiguous content model: when the parser reach element A, he can't determine 
wether it is a single A element or part of AB group.

Reversing A and B order in group won't fix the problem, but anything else that 
would allows to distinguish them would. Gregor, could we have a bit more 
context ?
-- 
No matter how good of a deal you get on computer components, the price will 
always drop immediately after the purchase. 
        -- Murphy's Computer Laws n°7

--Boundary-00=_GbLW+QK7EGgQ4BD
Content-Type: text/xml;
  charset="iso-8859-1";
  name="test.xml"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="test.xml"

<?xml version="1.0"?>
<Test
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="test.xsd">
  <!-- just A -->
  <Parent>
    <A/>
  </Parent>
  <!-- just B -->
  <Parent>
    <B/>
  </Parent>
  <!-- A and B -->
  <Parent>
    <A/>
    <B/>
  </Parent>
  <!-- Nada -->
  <Parent/>
</Test>

--Boundary-00=_GbLW+QK7EGgQ4BD
Content-Type: text/xml;
  charset="iso-8859-1";
  name="test.xsd"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="test.xsd"

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

  <xs:element name="Test">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="Parent" maxOccurs="unbounded"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:element name="Parent">
    <xs:complexType>
      <xs:choice>
        <xs:element ref="A"/>
        <xs:element ref="B"/>
        <xs:group ref="AB"/>
      </xs:choice>
    </xs:complexType>
  </xs:element>

  <xs:element name="A" type="xs:string"/>

  <xs:element name="B" type="xs:string"/>

  <xs:group name="AB">
    <xs:sequence>
      <xs:element ref="A"/>
      <xs:element ref="B"/>
    </xs:sequence>
  </xs:group>

</xs:schema>


More information about the tdwg-content mailing list