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

Re: XML Schemas: Best Practices

  • From: "Roger L. Costello" <costello@m...>
  • To: xml-dev@l...
  • Date: Mon, 08 Jan 2001 04:28:03 -0500

catalogue schema
Curt Arnold wrote:
> 
> The choice construct requires you to explicitly change the definition
> of the containing element which may be in a schema you do not 
> control. Substitution groups allow you to implicitly change the
> containing element at the definition of the contained element.

Wow! A few words with a lot of implications. This is really awesome!

I have spent a considerable amount of time thinking about the above
words. Below is a summary of what I have come to learn.
Please let me know if I have not understood all implications.

Implications of Method 1 versus Method 2 in terms of extensibility
of a variable content container element:

Recall Method 1 - it uses an abstract element and substitutionGroup
to implement a container element with variable content.

With Method 1 you can extend the set of elements that may be 
used in the variable content section, even if the schema is outside 
your control. For example, suppose that you do not have privilege 
to modify the Catalogue schema. Currently, the Catalogue 
schema only supports Book and Magazine elements in the variable 
content section. But your instance documents also need CD elements: 

   <Catalogue>
        <Book> ... </Book>
        <CD> ... </CD>
        <Magazine> ... </Magazine>
        <Book> ... </Book>
   </Catalogue>

How can you extend the Catalogue schema, without modifying it?

You can create your own independent schema which contains a 
declaration for CD that extends the PublicationType defined in the 
Catalogue schema, and joins the Publication substitutionGroup: 

    <import namespace="http://www.catalogue.org"
            schemaLocation="Catalogue.xsd"/>
    <complexType name="CDType">
        <complexContent>
            <extension base="c:PublicationType" >
                <sequence>
                    <element name="RecordingCompany" type="string"/>
                </sequence>
            </extension>
        </complexContent>
    </complexType>
    <element name="CD" substitutionGroup="c:Publication" 
             type="cd:CDType"/>

The CD element meets the requirements for being in Catalogue's variable 
content section - its type derives from the PublicationType, and 
it is a member of the Publication substitutionGroup. Thus, instance 
documents may now use Book, Magazine, or CD in the variable content 
section - provided, of course, instance documents specify this new 
CD schema as well as the Catalogue schema in its schemaLocation: 

    xsi:schemaLocation = "http://www.catalogue.org
                          Catalogue.xsd
                          http://www.cd.org
                          CD.xsd"

Thus, we see that this method (Method 1) allows us to extend the 
Catalogue schema, without modifying it. Wow!

Now consider Method 2 - use a repeatable <choice> element to implement
a container element with variable content.

Again, suppose that the Catalogue schema is outside your control. 
Currently the variable content section only supports Book and Magazine. 
Your instance documents needs CD as well as Book and Magazine, e.g., 

    <Catalogue>
        <Book> ... </Book>
        <CD> ... </CD>
        <Magazine> ... </Magazine>
        <Book> ... </Book>
    </Catalogue>

This method requires that the element in the Catalogue schema be 
modified to include the CD element. However, the Catalogue schema 
may be outside your control, so you may not be able to get it 
extended to include the CD element. Thus, this method has serious 
restrictions on its extensibility. 

This is so cool!  /Roger


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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-2013 All Rights Reserved.