[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: Jeff Rafter <jeffrafter@e...>
  • Date: Tue, 06 Mar 2001 06:29:51 -0500

chameleon animal
Thanks for all your comments Jeff.  Let me try to reply to your
questions.  [Note: this week I feverishly working on summarizing all
these issues and posting them on my web site.  I hope to have it
completed by Friday.]

> > <?xml version="1.0"?>
> > <schema xmlns="http://www.w3.org/2000/10/XMLSchema"
> >         targetNamespace="http://www.library.org"
> >         xmlns:lib="http://www.library.org"
> >         elementFormDefault="qualified">
> >     <include schemaLocation="BookCatalogue.xsd"/>
> >     <element name="Library">
> >         <complexType>
> >              <sequence>
> >                  <element name="BookCatalogue">
> >                      <complexType>
> >                          <sequence>
> >                              <element ref="lib:Book"
> >                                 minOccurs="0" 
> >                                 maxOccurs="unbounded"/>
> >                          </sequence>
> >                      </complexType>

> Should there be a closing element tag here?  I don't think this is 
> important for sake of the example-- only if this exact example is
> published as a Best Practice.  (The WF error also occurs in 
> Approach 2).

Thanks, I'll make certain that the online version is correct.

> > Before describing why I believe that approach 2 is better, we 
> > need to first revisit Chameleon components.
> >
> > Components that are in a schema with no targetNamespace have a very
> > interesting property: when they are <include>d in a schema that has 
> > a targetNamespace then those no-namespace components take on the 
> > namespace of the <include>ing schema.  They "blend into the 
> > background" just like a Chameleon.  Thus, the no-namespace 
> > components are called Chameleon components.
> >
> > In the above schemas there is an <include> element to bring in the
> > components in BookCatalogue.xsd.  Let's consider how the above
> > approaches behave when the schema being <include>d 
> > (BookCatalogue.xsd) has no namespace.  Here is BookCatalogue.xsd:
> 
> Wow, what a great description.  Do you happen to have any other 
> references for this?  

Thanks! Yes, we discussed the Chameleon design approach quite a bit in
the Zero, One, or Many Namespaces issue.  See: 

     http://www.xfront.com/ZeroOneOrManyNamespaces.html

> It seems as though stuff like this may in fact affect other Best
> Practices or decisions therein.  This also seems like a good one for 
> the Schema FAQ-- What is a chameleon component?

A Chameleon component is a component (element, simpleType, complexType,
attribute, attributeGroup, or modelGroup) in a no-namespace schema. 
They are called "Chameleon" because they have the property of taking on
the namespace of a schema which <include>s them (just like a Chameleon
animal is able to blend into its surroundings)  (Good question Jeff, I
have never explicitly defined this.  Thanks.)
 
> (are you going to give a prefix as best practice? e.g. "xsd:" 
> <ducks/>)--

Uh, no (but I like xsd).
 
> Is there an Approach 3? (a.k.a. is this even right?)

Yes, good point.  I forgot about that.  As you mention, Approach 3 is to
have no default namespace, and explicitly qualify everything.  Below is
shown this approach:

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
        targetNamespace="http://www.library.org"
        xmlns:lib="http://www.library.org"
        elementFormDefault="qualified">
    <xsd:include schemaLocation="BookCatalogue.xsd"/>
    <xsd:complexType name="LocalType">
         <xsd:sequence>
              <xsd:element name="LocalElement" type="xsd:string"
                minOccurs="0" maxOccurs="unbounded"/>
         </xsd:sequence>
    </xsd:complexType>
    <xsd:element name="Library">
        <xsd:complexType>
             <xsd:sequence>
                  <xsd:element name="BookCatalogue">
                     <xsd:complexType>
                         <xsd:sequence>
                             <xsd:element ref="lib:Book"
                                minOccurs="0" maxOccurs="unbounded"/>
                             <xsd:element name="somelocalelement"
                                          type="lib:LocalType"
                                          minOccurs="0" 
                                          maxOccurs="unbounded"/>
                         </xsd:sequence>
                     </xsd:complexType>
                 </xsd:element>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>

> Notice niether Book or LocalType are prefixed because there is no 
> default namespace.  

No, with Approach 3 you need to explicitly qualify all references -
lib:Book, lib:LocalType - since there is no default namespace.

Thanks for the comments!  /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.