XML Namespaces

XML Foundations [./]
Fall 2009 — INFO 242 (CCN 42575)

Erik Wilde, UC Berkeley School of Information
2009-09-17

Creative Commons License [http://creativecommons.org/licenses/by/3.0/]

This work is licensed under a CC
Attribution 3.0 Unported License
[http://creativecommons.org/licenses/by/3.0/]

Contents E. Wilde: XML Namespaces

Contents

E. Wilde: XML Namespaces

(2) 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.



How to think about Namespaces

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]
How to think about Namespaces E. Wilde: XML Namespaces

(4) Namespaces are Simple



How to think about Namespaces E. Wilde: XML Namespaces

(5) 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>


How to think about Namespaces E. Wilde: XML Namespaces

(6) Name Spaces



How to think about Namespaces E. Wilde: XML Namespaces

(7) URI Philosophy



How to think about Namespaces E. Wilde: XML Namespaces

(8) The Namespace Problem



Using Namespaces

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]
Using Namespaces E. Wilde: XML Namespaces

(10) Declaring Namespaces



Using Namespaces E. Wilde: XML Namespaces

(11) Unhealthy Namespace Usages



Using Namespaces E. Wilde: XML Namespaces

(12) 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>


Using Namespaces E. Wilde: XML Namespaces

(13) Elements and Attributes



Using Namespaces E. Wilde: XML Namespaces

(14) Other Usages

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


Defining Namespaces

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]
Defining Namespaces E. Wilde: XML Namespaces

(16) Any URI is Possible



Defining Namespaces E. Wilde: XML Namespaces

(17) Namespace Definitions



Defining Namespaces E. Wilde: XML Namespaces

(18) Structured Namespaces



Defining Namespaces E. Wilde: XML Namespaces

(19) Fixed or Extensible?



Defining Namespaces E. Wilde: XML Namespaces

(20) Namespace Descriptions

ns-description.png

Erik Wilde, Structuring Namespace Descriptions, 15th International World Wide Web Conference (WWW2006), Edinburgh, UK, May 2006. [http://dret.net/netdret/publications#wil06h]



Processing Namespaces

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]
Processing Namespaces E. Wilde: XML Namespaces

(22) Namespaces and Validity



Processing Namespaces E. Wilde: XML Namespaces

(23) 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>


Processing Namespaces E. Wilde: XML Namespaces

(24) Namespaces in the Tree

xmlns-tree.png

Conclusions

Outline (Conclusions)

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

(26) Name Spaces



2009-09-17 XML Foundations [./]
Fall 2009 — INFO 242 (CCN 42575)