W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2002

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

From: Laurens van den Oever <laurens@Q42.nl>
Date: Mon, 29 Jul 2002 11:28:36 -0400 (EDT)
Message-ID: <E45658F2AAA3AF4A9CE4B5E7EAA70B2D0124B3@SOUTHERNCOMFORT.Q42.nl>
To: <www-dom@w3.org>

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 Schema:
<xs:element name="parent">
    <xs:choice minOccurs="2" maxOccurs="2">
      <xs:element name="childA" type="xs:string"/>
      <xs:element name="childB" type="xs:string"/>
<xs:element name="ancestor">
      <xs:element ref="parent" minOccurs="0"/>
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:element ref="caption" minOccurs="0"/>
        <xs:element ref="col" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element ref="colgroup" minOccurs="0" maxOccurs="unbounded"/>
          <xs:element ref="thead" minOccurs="0"/>
          <xs:element ref="tfoot" minOccurs="0"/>
          <xs:element ref="tbody" maxOccurs="unbounded"/>
          <xs:element ref="tr" maxOccurs="unbounded"/>
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.
Laurens van den Oever
Received on Monday, 29 July 2002 16:08:18 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:50:33 UTC