Download presentation
Presentation is loading. Please wait.
1
The Purpose of XML Namespaces
2
Namespace Caveats XML namespaces are the source of criticism and confusion XML namespaces are the source of many myths .NET namespaces and XML namespaces are not the same thing In fact, they have nothing to do with each other
3
The Problem of Name Ambiguity
Names can be ambiguous When we say “Las Vegas” do we mean “Las Vegas, Nevada” or “Las Vegas, New Mexico” How many cities have the name “Springfield”? When we say address, do we mean street address or Internet address Name ambiguity occurs when two XML documents have elements of the same name but with different meanings
4
The Problem of Name Ambiguity (Example)
<?xml version="1.0" encoding="utf-8" ?> <office> <address>123 Oak street</address> <address> </address> </office> The meaning of <address> differs between the two contexts
5
The Purpose of XML Namespaces (1)
They eliminate name ambiguity in element names between documents Namespaces answer the question “Are we talking about the same thing?” XML namespaces were released about 1 year after XML itself was released They don’t quite work right with DTDs Namespaces are the reason why we don’t use the colon (:) in element names
6
The Implementation of XML Namespaces (1)
XML namespaces use URIs (IRIs) to qualify element names This allows us to use the same element name with a different URI thereby qualifying the element name The URI is just a globally unique name Formally, XML namespaces define a vocabulary or universe of names
7
Namespaces (Quotable Quotes)
What Does a Namespace URL Locate? There is nothing at all at the end of a namespace URI, except perhaps a 404 Not Found error
8
IT’S JUST A NAME Namespaces (Myths) IT’S NOT NECESSARILY A WEB SITE
IT’S NOT A REFERENCE TO A PROGRAM ON THE WEB IT’S NOT A POINTER TO A RESOURCE IT’S JUST A NAME
9
Applications using XML namespaces
XML namespaces are widely used in The Schema Definition Language (XSDL) The Extensible Stylesheet Language (XSL) To describe the schema of an Office 2007 document A .NET DataSet
10
Namespaces (Illustration)
Namespace (vocabulary) XSD Parser Namespace (vocabulary) XSLT Namespace (vocabulary) Other Your document
11
Characteristics of Namespace URIs
You should control the URI that you use or you can’t control the name It can be any URI whether or not the URI exists on the Web Thus, the URI has no relevance URIs are case sensitive URIs are identical only if the strings are identical No %-escaping is done
12
Characteristics of Namespace URIs (Example)
The following URIs ARE different: And so are the following:
13
The XML Namespace Now it should be clear what xml:lang is
The prefix xml is always bound to the namespace name OK – this one points to a URI but it does not have to! You can declare this namespace but it is not necessary If declared, you cannot bind xml: to another namespace URI
14
The Implementation of Namespaces (1)
Namespace names are defined through ‘special’ attributes Any attribute starting with the prefix xmlns: is considered a prefix defining attribute The prefix following the attribute is the local abbreviation for the namespace The prefix name has no relevance although there are common naming conventions The attribute value is a unique URI
15
The Implementation of Namespaces (Example 1)
The following shows three namespace declarations The prefix off is associated with the namespace <off:office xmlns:off=" xmlns:phys=" xmlns:net=" </off:office> Qualified name <off/office>
16
Applying Namespaces to Attributes
Attributes can apply to a namespace The default namespace does NOT apply to attribute names
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.