[XMLSCHEMA-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Referencing Variations

From: Gavin Kistner <gavin.kistner@anark.com>
Date: Fri, 21 Apr 2006 12:21:06 -0600
Message-ID: <E6A2B94B67BF4D4183BED2627746906D03131E09@asimov.anark.com>
To: <xmlschema-dev@w3.org>
james name 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 GMT

Subscribe to the Stylus Scoop newsletter for helpful XML tips and tutorials.
Email
First Name
Last Name
Company

Download Stylus Studio 6 XML Enterprise Edition

Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.