Section 2.6.  Namespaces

Prev don't be afraid of buying books Next

2.6. Namespaces

There is a problem that arises when you allow anybody to pick names as XML does. The problem is that different people in different places will invariably use the same names for different things. This makes it very difficult to build systems that work with documents from multiple independent sources because a publisher could use the element-type name PAR to mean paragraph while a military vocabulary could use an element type with the same name to mean paratrooper. A mathematician might use an element type with that name to label paradoxes!

2.6.1 Prefixes

There is a standard that addresses this problem. It is known as Namespaces in XML.

A namespace is a conceptual universe within which a defined term – a name – is unique. An XML namespace is slightly different: it is divided into namespace partitions for different kinds of names so that, for example, an element-type name can be the same as an attribute name.

Within a namespace partition (also called a symbol space), each name is unique. It is declared only once and the declared definition applies wherever in the scope of the namespace partition the name is used.

A vocabulary is a namespace. Without the namespaces standard, a document type could only have a single vocabulary, consisting of its element-type and attribute names. The standard lets you mix vocabularies in a document by creating vocabulary nicknames (i.e. abbreviations) that you can prefix to the names to show the vocabulary to which they belong.

For example, you might choose to prefix names from a meteorological information vocabulary with met:. So a document might have elements such as met:temperature, met:humidity and so forth. It could also have health:temperature, from a different vocabulary. To the computer, met:temperature and health:temperature are clearly different names.

2.6.2 Identifiers

Of course, this solution appears to create its own problem: How can you be sure that different XML designers will use met to refer to the same vocabulary? The short and happy answer is: They don't have to!

That's because within your document met – which, remember, is just a nickname – is associated with an unambiguous identifier of the vocabulary. That identifier is a URI reference and could look something like http://www.weatherworld.com. Other documents might use a different abbreviation for that vocabulary or use met: to prefix a different vocabulary.

In practice, though, vocabulary developers recommend prefixes and people tend to use the recommended ones.

Note

The URI of a namespace does not have to address a real Web page. The Web addressing system is just being used as a namespace within which all URIs – and therefore namespace names – are unique.




Amazon


XML in Office 2003. Information Sharing with Desktop XML
XML in Office 2003: Information Sharing with Desktop XML
ISBN: 013142193X
EAN: 2147483647
Year: 2003
Pages: 176

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net