[
Lists Home |
Date Index |
Thread Index
]
- From: Roger Costello <costello@mitre.org>
- To: XML-DEV@xml.org
- Date: Sat, 01 Jul 2000 11:07:07 -0400
Hi Folks,
I just don't grok[1] this elementFormDefault stuff. Sure, I can blindly
follow the rules stated in the spec, but I don't know the reasoning
behind why I use it one way or the other
(elementFormDefault="unqualified" versus
elementFormDefault="qualified").
[1] From "Stranger in a Strange Land" by Robert Heinlein. It means "to
understand, empathize deeply".
Let me try to explain my confusion. Here is the portion of the spec
that discusses the elementFormDefault stuff:
"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:
<?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?
[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:
"When local elements and attributes are not required to be qualified, an
instance author may require more or less knowledge about the details of
the schema to create schema valid instance documents. More specifically,
if the author can be sure that only the root element (such as
purchaseOrder) is global, then it is a simple matter to qualify only the
root element. Alternatively, the author may know that all the elements
are declared globally, and so all the elements in the instance document
can be prefixed, perhaps taking advantage of a default namespace
declaration. (We examine this approach in Section 3.3). On the other
hand, if there is no uniform pattern of global and local declarations,
the author will need detailed knowledge of the schema to correctly
prefix global elements (and attributes)."
The Primer is great, but for this stuff I am not able to grasp what it
is trying to say.
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? /Roger
***************************************************************************
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/
***************************************************************************
|