Referencing Variations

I have an XML file that looks something like this:

<root>
   <scene>
      <a foo="1" bar="yay" s="yum">
         <b jim="x" jam="1 2" s="yum"/>
         <a foo="1" bar="yay" s="yum">
            <a foo="1" bar="yay" s="yum"/>
            <b jim="x" jam="1 2" s="yum">
               <a foo="1" bar="yay" s="yum"/>
            </b>
         </a>
      </a>
   </scene>
   <library>
      <a foo="1" bar="yay" />
      <b jim="x" jam="1 2" />
   </library>
</root>

Everywhere the 'a' element shows up, it has the same set of common
attributes.
Everywhere the 'b' element shows up, it has the same set of common
attributes.

When 'a' or 'b' appear within the 'scene' element, they:
  * Have some extra attributes available
  * Are allowed to have a bunch of children, including themselves

How can I do this? I figure that I want to create global complexTypes
that get referenced by the elements in each scope, but then I'm at a
loss for how to reference those elements.

Following is my failed attempt at a schema for the above sample:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema
		xmlns:xs="http://www.w3.org/2001/XMLSchema"
		elementFormDefault="qualified">
  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>

        <xs:element name="scene">
          <xs:complexType>
            <xs:choice maxOccurs="unbounded">
              <xs:element name="a">
                <xs:complexType>
                  <xs:complexContent>
                    <xs:extension base="a">
                      <xs:choice maxOccurs="unbounded">
                        <!-- I want to recursively refer to
                             the definitions of 'a' and 'b'
                             within the 'scene' scope -->
                        <xs:element ref="a" />
                        <xs:element ref="b" />
                      </xs:choice>
                      <xs:attributeGroup ref="scene-attributes" />
                    </xs:extension>
                  </xs:complexContent>
                </xs:complexType>
              </xs:element>
              
              <xs:element name="b">
                <xs:complexType>
                  <xs:complexContent>
                    <xs:extension base="b">
                      <xs:choice maxOccurs="unbounded">
                        <!-- I want to recursively refer to
                             the definitions of 'a' and 'b'
                             within the 'scene' scope -->
                        <xs:element ref="a" />
                        <xs:element ref="b" />
                      </xs:choice>
                      <xs:attributeGroup ref="scene-attributes" />
                    </xs:extension>
                  </xs:complexContent>
                </xs:complexType>
              </xs:element>
            </xs:choice>
          </xs:complexType>
        </xs:element>

        <xs:element name="library">
          <xs:complexType>
            <xs:choice maxOccurs="unbounded">
              <xs:element name="a">
                <xs:complexType>
                  <xs:complexContent>
                    <xs:extension base="a" />
                  </xs:complexContent>
                </xs:complexType>
              </xs:element>
            </xs:choice>
          </xs:complexType>
        </xs:element>

      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <xs:complexType name="a">
    <xs:attribute name="foo" use="required" type="xs:integer" />
    <xs:attribute name="bar" use="required" type="xs:string" />
  </xs:complexType>

  <xs:complexType name="b">
    <xs:attribute name="jim" use="required" type="xs:string" />
    <xs:attribute name="jam" use="required" type="xs:integer" />
  </xs:complexType>

  <xs:attributeGroup name="scene-attributes">
    <xs:attribute name="s" type="xs:string" fixed="yum" />
  </xs:attributeGroup>

</xs:schema>

Received on Friday, 21 April 2006 18:21:27 UTC