Datasheet

default namespace. There is no way to get one "automatically". If you don’t define a default namespace,
and then you write an unprefixed element or attribute, that element or attribute is in no namespace at
all.
Namespace prefixes can be declared on any element in a document, not just the root element. This
includes changing the default namespace. If you declare a prefix that has been declared on an ancestor
element, then the new prefix declaration works for the element where it’s declared and all its child ele-
ments.
You may declare multiple prefixes for the same namespace URI. Doing so is perfectly allowable; how-
ever, remember that namespace equality is based on the namespace URI, not the namespace prefix.
Thus elements that look like they should be in the same namespace can actually be in different name-
spaces. It all depends on which URI the namespace prefixes have been bound to. Also note that certain
namespaces have commonly accepted uses, such as the xsi prefix used in this example. Here are some of
the more common prefixes:
Namespace Prefix Namespace URI Usage
xsi http://www.w3.org/2001/XMLSchema-instance XML Schema Instance
xsd http://www.w3.org/2001/XMLSchema XML Schema
xsl http://www.w3.org/1999/XSL/Transform XSLT
fo http://www.w3.org/1999/XSL/Format XSL Formatting
Objects
xlink http://www.w3.org/1999/xlink XLink
svg http://www.w3.org/2000/svg Scalable Vector
Graphics
ds http://www.w3.org/2000/09/xmldsig# XML Signature
xenc http://www.w3.org/2001/04/xmlenc# XML Encryption
Validity
The second rule for XML documents is validity. It’s a little odd to say "rule" because XML documents
don’t have to be valid, but there are well defined rules that say what it means for a document to be valid.
Validity is the next step up from well-formedness. Validity lets you say things like this: Every book ele-
ment must have a title element followed by an author element, followed by an isbn element, and so on.
Validity says that the document is valid according to the rules of some grammar. (Remember diagram-
ming sentences in high-school English? It’s the same kind of thing we’re talking about here for valid
XML documents.)
Because a document can only be valid according to the rules of a grammar, you need a way to describe
the grammar the XML document must follow. At the moment, there are three major possibilities: DTDs,
the W3C’s XML Schema, and OASIS’s Relax-NG.
4
Chapter 1
01 543555 Ch01.qxd 11/5/03 9:40 AM Page 4