OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help



   Re: XML-Schemas: purpose of elementFormDefault?

[ Lists Home | Date Index | Thread Index ]
  • From: ht@cogsci.ed.ac.uk (Henry S. Thompson)
  • To: Roger Costello <costello@mitre.org>
  • Date: 03 Jul 2000 14:30:31 +0100

Roger Costello <costello@mitre.org> writes:

> "Element items validated by a global declaration must be qualified with
> a namespace URI. Control over whether element items validated by a local
> declaration must be namespace-qualified or not is provided by the form
> [attribute], whose default is provided by the elementFormDefault
> [attribute] on the enclosing schema, via its determination of {target
> namespace}"
> What I learned from this is best explained with an example. Here's a
> schema with one global element declaration and several local element
> declarations:
> <?xml version="1.0"?>
> <!DOCTYPE schema SYSTEM "part1.dtd">
> <schema xmlns="http://www.w3.org/1999/XMLSchema"
> targetNamespace="http://www.publishing.org/namespaces/BookCatalogue"
>       elementFormDefault="unqualified">
>     <element name="BookCatalogue">
>         <complexType>
>              <sequence>
>                  <element name="Book" minOccurs="0"
> maxOccurs="unbounded">
>                      <complexType>
>                          <sequence>
>                              <element name="Title" type="string" 
>                                       minOccurs="1" maxOccurs="1"/>
>                              <element name="Author" type="string" 
>                                       minOccurs="1" maxOccurs="1"/>
>                              <element name="Date" type="string" 
>                                       minOccurs="1" maxOccurs="1"/>
>                              <element name="ISBN" type="string" 
>                                       minOccurs="1" maxOccurs="1"/>
>                              <element name="Publisher" type="string" 
>                                       minOccurs="1" maxOccurs="1"/>
>                          </sequence>
>                      </complexType>
>                  </element>
>             </sequence>
>         </complexType>
>     </element>
> </schema>
> My understanding is that since elementFormDefault is set to
> "unqualified" that means in the instance document I do not have to (must
> not?) qualify the local elements:

Must not.

> <?xml version="1.0"?>
> <b:BookCatalogue 
>         xmlns:b="http://www.publishing.org/namespaces/BookCatalogue"
>         xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"
>         xsi:schemaLocation=
>                   "http://www.publishing.org/namespaces/BookCatalogue
>                    BookCatalogue2.xsd">
>         <Book>
>                 <Title>My Life and Times</Title>
>                 <Author>Paul McCartney</Author>
>                 <Date>1998</Date>
>                 <ISBN>94303-12021-43892</ISBN>
>                 <Publisher>McMillin Publishing</Publisher>
>         </Book>
>         ...
> </b:BookCatalogue>
> Notice how I have qualified the global element (BookCatalogue) but not
> the local elements (Book, Title, Author, Date, ISBN, Publisher).
> Now I can explain where I am confused:  
> [1] Does this mean that only the global element (BookCatalogue) gets
> validated, and not the local elements (Book, Title, Author, Date, ISBN,
> Publisher)?  If so, why would you ever want to do that - what's the
> value of the schema in such a case?

Nope, everything is validated.

> [2] It seems to me that when you create the schema, and you give a value
> for targetNamespace, then all the elements declared in the schema (both
> global and local elements) are associated with that namespace.  Is this
> not true?  So, why would you not  want to associate the local elements
> with the namespace in the instance document? The Primer tries to justify
> why you might want to do this, but I found the explanation less than
> satisfying:

Associated with, yes.  Literally 'in', not clearly.  Consider
attributes.  They are 'associated' with the namespace of their parent, 
but they're not directly 'in' it, because there can be two or more
attributes with different parents but the same name which are clearly
different, with different declarations.  Just so locally declared
elements -- they are associated with a namespace via their ancestry,
but not directly 'in' it, for the same reason:  the potential of
multiple different declarations.

> To summarize, I can be a technician and blindly follow the rules - if
> the schema states elementFormDefault="unqualified" then just qualify the
> global elements in the instance document; if the schema states
> elementFormDefault="qualified" then qualify all elements in the instance
> document.  But I have no clue as to why I am doing this, when to do one
> versus the other, and what it means in terms of validation.  Can someone
> please enlighten me?

The intention is to allow the style of your _instances_, as regards
element qualification, to be independent of the style of your
_schemas_, as regards local vs top-level element declaration.

Without the control given by the 'form' attribute (and
'xxxFormDefault'), one of two situations would obtain in instances:

1) elements declared locally are like attributes: unqualified;
2) elements declared locally are like elements declared at the
   top-level: qualified (leaving the no-namespace-at-all case to one

There are clearly problems with (1), for instance because it means
that changing from a local to a global declaration for an element
will have an impact on the appearance of valid instances;

There are clearly problems with (2), because it violates the
parallelism between locally declarated elements and attributes, and
requires excessive prefixation in multi-namespace documents.

The current design is a compromise to allow experimentation with the
options.  You pays your money and you takes your choice.  There's no
difference with respect to validation:  schema-validation is attempted 
on everything declared, regardless of where/how.

  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
          W3C Fellow 1999--2001, part-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/

This is xml-dev, the mailing list for XML developers.
To unsubscribe, mailto:majordomo@xml.org&BODY=unsubscribe%20xml-dev
List archives are available at http://xml.org/archives/xml-dev/


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS