Bag Element

I have to agree with the previous posters comments on bag elements.  While 
this construct is possible to accomplish with existing constructs, they are 
essentially unusable for such a common construct.

The following accomplishes what a bag element would accomplish for the head 
element in XHTML 1.0, though I find this very unwieldy.

  <xs:group name="head.misc">
    <xs:sequence>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="script"/>
        <xs:element ref="style"/>
        <xs:element ref="meta"/>
        <xs:element ref="link"/>
        <xs:element ref="object"/>
      </xs:choice>
    </xs:sequence>
  </xs:group>

  <xs:element name="head">
    <xs:annotation>
      <xs:documentation>
      content model is "head.misc" combined with a single
      title and an optional base element in any order
      </xs:documentation>
    </xs:annotation>
    <xs:complexType>
      <xs:sequence>
        <xs:group ref="head.misc"/>
        <xs:choice>
          <xs:sequence>
            <xs:element ref="title"/>
            <xs:group ref="head.misc"/>
            <xs:sequence minOccurs="0">
              <xs:element ref="base"/>
              <xs:group ref="head.misc"/>
            </xs:sequence>
          </xs:sequence>
          <xs:sequence>
            <xs:element ref="base"/>
            <xs:group ref="head.misc"/>
            <xs:element ref="title"/>
            <xs:group ref="head.misc"/>
          </xs:sequence>
        </xs:choice>
      </xs:sequence>
      <xs:attributeGroup ref="i18n"/>
      <xs:attribute name="id" type="xs:ID"/>
      <xs:attribute name="profile" type="URI"/>
    </xs:complexType>
  </xs:element>

Something better would be:
<xs:element name="head">
    <xs:annotation>
        <xs:documentation>
        content model is "head.misc" combined with a single
        title and an optional base element in any order
        </xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:bag>
            <xs:element ref="title"/>
            <xs:element ref="base" minOccurs="0"/>
            <xs:element ref="script" minOccurs="0" maxOccurs="unbouned"/>
            <xs:element ref="style" minOccurs="0" maxOccurs="unbouned"/>
            <xs:element ref="meta" minOccurs="0" maxOccurs="unbouned"/>
            <xs:element ref="link" minOccurs="0" maxOccurs="unbouned"/>
            <xs:element ref="object" minOccurs="0" maxOccurs="unbouned"/>
        </xs:bag>
        <xs:attributeGroup ref="i18n"/>
        <xs:attribute name="id" type="xs:ID"/>
        <xs:attribute name="profile" type="URI"/>
    </xs:complexType>
</xs:element>

A couple of positive points of the bag construct (though I might rename it).
1) Increased readability and ease of authoring.
2) No longer requires tricks and can be contained in a single xs:element 
element.

Increased readability and usability should be enough to introduce this 
construct, but even if it isn't then two is a nice addition.

Orion Adrian

_________________________________________________________________
Get tax tips, tools and access to IRS forms – all in one place at MSN Money! 
http://moneycentral.msn.com/tax/home.asp

Received on Tuesday, 23 March 2004 18:04:49 UTC