XML Namespaces

XML Foundations [./]
Fall 2011 — INFO 242 (CCN 42596)

Ray Larson, UC Berkeley School of Information
2011-09-20

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 R. Larson: XML Namespaces

Contents

R. Larson: 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 [4]
  4. Processing Namespaces [3]
  5. Conclusions [1]
How to think about Namespaces R. Larson: XML Namespaces

(4) Namespaces are Simple



How to think about Namespaces R. Larson: 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 R. Larson: XML Namespaces

(6) Name Spaces



How to think about Namespaces R. Larson: XML Namespaces

(7) URI Philosophy



How to think about Namespaces R. Larson: 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 [4]
  4. Processing Namespaces [3]
  5. Conclusions [1]
Using Namespaces R. Larson: XML Namespaces

(10) Declaring Namespaces



Using Namespaces R. Larson: XML Namespaces

(11) Unhealthy Namespace Usages



Using Namespaces R. Larson: 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 R. Larson: XML Namespaces

(13) Elements and Attributes



Using Namespaces R. Larson: 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 [4]
  4. Processing Namespaces [3]
  5. Conclusions [1]
Defining Namespaces R. Larson: XML Namespaces

(16) Any URI is Possible



Defining Namespaces R. Larson: XML Namespaces

(17) Namespace Definitions



Defining Namespaces R. Larson: XML Namespaces

(18) Structured Namespaces



Defining Namespaces R. Larson: XML Namespaces

(19) Fixed or Extensible?



Processing Namespaces

Outline (Processing Namespaces)

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

(21) Namespaces and Validity



Processing Namespaces R. Larson: XML Namespaces

(22) 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 R. Larson: XML Namespaces

(23) Namespaces in the Tree

xmlns-tree.png

Conclusions

Outline (Conclusions)

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

(25) Name Spaces



2011-09-20 XML Foundations [./]
Fall 2011 — INFO 242 (CCN 42596)