DOM 3 Validation: creating nodes, required children and <xsd:choice/>

Hi,
 
While evaluating the proposed standard, I stumbled upon another problem:
the creation of nodes and especially the required children and
attributes of elements and the use of <xsd:choice/> in XML Schemas.
 
For instance:
 
XML:
 
<ancestor/>
 
XML Schema:
 
<xs:element name="parent">
  <xs:complexType>
    <xs:choice minOccurs="2" maxOccurs="2">
      <xs:element name="childA" type="xs:string"/>
      <xs:element name="childB" type="xs:string"/>
    </xs:choice>
  <xs:complexType>
</xs:element>
 
<xs:element name="ancestor">
  <xs:complexType>
    <xs:sequence>
      <xs:element ref="parent" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
 
In this case the <ancestor/> element's getChildElements() method will
return a NodeList with one element: <parent/>. However, inserting this
<parent/> element will not result in valid XML since the <parent/>
element needs at least two children. Attributes with use=required pose
similar problems. Both an getRequiredChildElements() method or adding
the required children to the elements in the getChildElements() NodeList
can solve this problem.
 
However, <parent/> is valid in four different configurations and I'd
like to let the user choose the one to use. The <xs:choice/> element is
quite a challenge for validating XML editors. Especially when nested.
See for example the table declaration in the XHTML schema:
 
  <xs:group name="table.content">
    <xs:sequence>
      <xs:element ref="caption" minOccurs="0"/>
      <xs:choice>
        <xs:element ref="col" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element ref="colgroup" minOccurs="0" maxOccurs="unbounded"/>
      </xs:choice>
      <xs:choice>
        <xs:sequence>
          <xs:element ref="thead" minOccurs="0"/>
          <xs:element ref="tfoot" minOccurs="0"/>
          <xs:element ref="tbody" maxOccurs="unbounded"/>
        </xs:sequence>
        <xs:choice>
          <xs:element ref="tr" maxOccurs="unbounded"/>
        </xs:choice>
      </xs:choice>
    </xs:sequence>
  </xs:group>
 
Most choices don't have to be resolved, but the choice between a
<table/> with <tbody/> children and a <table/> with <tr/> children has
to be made in order to get the document valid.
 
Greetings, 
 
Laurens van den Oever

Received on Monday, 29 July 2002 16:08:18 UTC