XML Namespaces

XML Foundations (INFO 242)

Erik Wilde, UC Berkeley School of Information
2007-09-18
Creative Commons License

This work is licensed under a CC
Attribution 3.0 Unported License

Abstract

XML is successful because it can be used in many different scenarios, and because it is easy to define a schema (such as a DTD) for new scenarios, producing a tailored XML data model for this scenario. This means that names in XML documents must be interpreted as belonging to a certain schema. As long as a document uses names from only one schema, this can be done rather easily. However, in many scenarios today documents combine names from different schemas, and XML Namespaces provide a mechanism how the names in an XML document can be associated with a namespace.

Outline (How to think about Namespaces)

  1. How to think about Namespaces [5]
  2. Using Namespaces [5]
  3. Defining Namespaces [5]
  4. Processing Namespaces [3]
  5. Conclusions [1]

Namespaces are Simple

Simple Examples

<html xmlns="http://www.w3.org/1999/xhtml">
 <body>
  <p>Some MathML Formula:</p>
  <math xmlns="http://www.w3.org/1998/Math/MathML">
   <mfrac>
<html xmlns="http://www.w3.org/1999/xhtml">
 <body>
  <p>Some MathML Formula:</p>
  <math:math xmlns:math="http://www.w3.org/1998/Math/MathML">
   <math:mfrac>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:math="http://www.w3.org/1998/Math/MathML">
 <body>
  <p>Some MathML Formula:</p>
  <math:math>
   <math:mfrac>
<html:html xmlns:html="http://www.w3.org/1999/xhtml" xmlns:math="http://www.w3.org/1998/Math/MathML">
 <html:body>
  <html:p>Some MathML Formula:</html:p>
  <math:math>
   <math:mfrac>

Name Spaces

URI Philosophy

The Namespace Problem

Outline (Using Namespaces)

  1. How to think about Namespaces [5]
  2. Using Namespaces [5]
  3. Defining Namespaces [5]
  4. Processing Namespaces [3]
  5. Conclusions [1]

Declaring Namespaces

Unhealthy Namespace Usages

Unhealthy Namespace Usages in Practice

<neurotic>
 <prefix:elem xmlns:prefix="http://ns1.com/">
  <prefix:child>content</prefix:child>
 </prefix:elem>
 <prefix:elem xmlns:prefix="http://ns2.com/">
  <prefix:child>content</prefix:child>
 </prefix:elem>
</neurotic>
<borderline>
 <prefix1:elem xmlns:prefix1="http://ns1.com/">
  <prefix1:child>content</prefix1:child>
 </prefix1:elem>
 <prefix2:elem xmlns:prefix2="http://ns1.com/">
  <prefix2:child>content</prefix2:child>
 </prefix2:elem>
</borderline>
<psychotic xmlns:prefix1="http://ns1.com/" xmlns:prefix2="http://ns1.com/">
 <prefix1:elem>
  <prefix2:child>content</prefix2:child>
 </prefix1:elem>
 <prefix2:elem>
  <prefix1:child>content</prefix1:child>
 </prefix2:elem>
</psychotic>

Elements and Attributes

Other Usages

<xsl:template match="section" xmlns:mathml="http://www.w3.org/1998/Math/MathML/">
<xsl:if test="exists(.//mathml:*)">

Outline (Defining Namespaces)

  1. How to think about Namespaces [5]
  2. Using Namespaces [5]
  3. Defining Namespaces [5]
  4. Processing Namespaces [3]
  5. Conclusions [1]

Any URI is Possible

Namespace Definitions

Structured Namespaces

Fixed or Extensible?

Namespace Descriptions

ns-description.png

Erik Wilde, Structuring Namespace Descriptions, 15th International World Wide Web Conference (WWW2006), Edinburgh, UK, May 2006.

Outline (Processing Namespaces)

  1. How to think about Namespaces [5]
  2. Using Namespaces [5]
  3. Defining Namespaces [5]
  4. Processing Namespaces [3]
  5. Conclusions [1]

Namespaces and Validity

Namespaces in the Document

<?xml version="1.0" encoding="UTF-8"?>
<html:html xmlns:html="http://www.w3.org/1999/xhtml" xmlns:math="http://www.w3.org/1998/Math/MathML">
 <html:body>
  <html:p>Some MathML Formula:</html:p>
  <math:math>
   <math:mfrac>
    <math:mn>2</math:mn>
    <math:mi>x</math:mi>
   </math:mfrac>
   <math:mo>=</math:mo>
   <math:mfrac>
    <math:mn>3</math:mn>
    <math:mi>y</math:mi>
   </math:mfrac>
  </math:math>
 </html:body>
</html:html>

Namespaces in the Tree

xmlns-tree.png

Outline (Conclusions)

  1. How to think about Namespaces [5]
  2. Using Namespaces [5]
  3. Defining Namespaces [5]
  4. Processing Namespaces [3]
  5. Conclusions [1]

Name Spaces