Namespaces


Namespaces

Elliotte Rusty Harold

Software Development 2001 West

Thursday, April 12, 2001

elharo@metalab.unc.edu

http://www.ibiblio.org/xml/


Raison d'etre

  1. To distinguish between elements and attributes from different vocabularies with different meanings.

  2. To group all related elements and attributes together so that a parser can easily recognize them.


The Need for Namespaces


Namespaces disambiguate elements


Namespace Syntax


Namespace URIs


Binding Prefixes to Namespace URIs


Binding Prefixes to Namespace URIs Example

<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
            xmlns:xlink="http://www.w3.org/1999/xlink">
  <xhtml:head><xhtml:title>Three Namespaces</xhtml:title></xhtml:head>
  <xhtml:body>
    <xhtml:h1 align="center">An Ellipse and a Rectangle</xhtml:h1>
    <svg:svg xmlns:svg="http://www.w3.org/2000/svg" 
             width="12cm" height="10cm">
      <svg:ellipse rx="110" ry="130" />
      <svg:rect x="4cm" y="1cm" width="3cm" height="6cm" />
    </svg:svg>
    <xhtml:p xlink:type="simple" 
      xlink:href="ellipses.html">
      More about ellipses
    </xhtml:p>
    <xhtml:p xlink:type="simple" xlink:href="rectangles.html">
      More about rectangles
    </xhtml:p>
    <xhtml:hr/>
    <xhtml:p>Last Modified February 13, 2000</xhtml:p>    
  </xhtml:body>
</xhtml:html>

Binding namespaces to prefixes with #FIXED ATTLIST declarations

<!ATTLIST svg:svg xmlns:svg (CDATA) #FIXED "http://www.w3.org/2000/svg">


<svg:svg width="12cm" height="10cm">
  <svg:ellipse rx="110" ry="130" />
  <svg:rect x="4cm" y="1cm" width="3cm" height="6cm" />
</svg:svg>

Unprefixed attributes are never in any namespace


URIs matter; not prefixes


Namespace URIs do not necessarily point to a document, page, or schema


The Default Namespace


Multiple default namespaces


Binding default namespaces to elements with #FIXED ATTLISTs

<!ATTLIST svg xmlns (CDATA) #FIXED "http://www.w3.org/2000/svg">


<svg width="12cm" height="10cm">
  <ellipse rx="110" ry="130" />
  <rect x="4cm" y="1cm" width="3cm" height="6cm" />
</svg>

How Parsers Handle Namespaces


Namespaces and DTDs


Parameter Entity References for Namespace Prefixes


Namespaces and Schemas


A Song with a Namespace

java.net.MalformedURLException: no protocol: 

A Schema for a Document that Uses the Default Namespace

java.net.MalformedURLException: no protocol: 

Multiple Namespaces, Multiple Schemas

java.net.MalformedURLException: no protocol: 

XLink Schema

java.net.MalformedURLException: no protocol: 

Song Schema with XLink Support

java.net.MalformedURLException: no protocol: 

What Goes at the end of a Namespace URI?

The flaw is the conflation of name, location and identity but that flaw is the basic feature by which the WWW runs so we are stuck there. All the handwaving about URN/URI/URL doesn't avoid the simple fact that if one puts http:// anywhere in browser display space, the system colors it blue and puts up a finger.

The monkey expects a resource and when it doesn't get one, it shocks the monkey. Monkeys don't read specs to find out why they should be shocked. They turn red and put up a finger.

--Claude L Bullard on the xml-dev mailing list


The Resource Description Discovery Language


The resource Element


Example RDDL resource Elements

For the http://www.cafeconleche.org/baseball/ namespace:

<rddl:resource xlink:href="baseball.css" 
    xlink:role="http://www.rddl.org/arcrole.htm#CSS">
  <div id="CSS" class="resource">
    <h3>CSS Stylesheet</h3>
    <p>A <a href="baseball.css">CSS stylesheet</a> 
    for baseball statistics documents.</p> 
  </div>
</rddl:resource>

<rddl:resource xlink:href="baseball.dtd"
    xlink:role="http://www.rddl.org/arcrole.htm#DTD">
  <div id="DTD" class="resource">
    <h3>DTD</h3>
    <p>A <a href="baseball.dtd">DTD</a> for , 
    baseball statistics</p>
  </div>
</rddl:resource>

An Example RDDL Document

<!DOCTYPE html PUBLIC "-//XML-DEV//DTD XHTML RDDL 1.0//EN" 
                      "http://www.openhealth.org/RDDL/rddl-xhtml.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:xlink="http://www.w3.org/1999/xlink"
      xmlns:rddl="http://www.rddl.org/">
<head>
<title>RDDL Resources for Baseball Statistics</title>
</head>
<body>
<h1>RDDL Resources for Baseball Statistics</h1>

<p>This is a sample RDDL document 
used in Elliotte Rusty Harold's seminars
including</p>

<ul>
  <li>XLinks and XPointers</li>
  <li>Namespaces in XML</li>
</ul>

<p>It describes resources related to
the baseball statistics DTD developed in the XML
Bible and located at the namespace 
<code>http://www.cafeconleche.org/baseball/</code>.</p>

<p>
<img src="../smallbiblecover.jpg" width="127" height='156'
  alt="Cover of the XMl Bible"/>
</p>

<rddl:resource xlink:href="baseball.css" 
    xlink:role="http://www.rddl.org/arcrole.htm#CSS">
  <div id="CSS" class="resource">
    <h3>CSS Stylesheet</h3>
    <p>A <a href="baseball.css">CSS stylesheet</a> 
    for baseball statistics documents.</p> 
  </div>
</rddl:resource>

<rddl:resource xlink:href="baseball.dtd"
    xlink:role="http://www.rddl.org/arcrole.htm#DTD">
  <div id="DTD" class="resource">
    <h3>DTD</h3>
    <p>A <a href="baseball.dtd">DTD</a> for , 
    baseball statistics</p>
  </div>
</rddl:resource>

<p>
Copyright 2001 <a href="http://www.macfaq.com/personal.html">Elliotte Rusty Harold</a><br class="empty"/>
<a href="mailto:elharo@metalab.unc.edu">elharo@metalab.unc.edu</a><br class="empty"/>
Last Modified Sunday, January 14, 2001
</p>

</body>
</html>
View in Browser

The xlink:href attribute


The xlink:role attribute


The xlink:arcrole attribute


The xlink:title attribute


The xlink:show and xlink:actuate attributes


Declarations for rddl:resource

<!ELEMENT rddl:resource (#PCDATA | %Flow.mix;)*>
<!ATTLIST rddl:resource
          id            ID       #IMPLIED
          xlink:type    (simple) #FIXED "simple"
          xmlns:rddl    CDATA    #FIXED 'http://www.rddl.org/'
          xml:lang      NMTOKEN  #IMPLIED
          xlink:arcrole CDATA    #IMPLIED
          xlink:href    CDATA    #IMPLIED
          xlink:role    CDATA    'http://www.rddl.org/#resource'
          xlink:title   CDATA    #IMPLIED
          xlink:embed   (none)   #FIXED "none"
          xlink:actuate (none)   #FIXED "none"
>

To Learn More


To Learn More


Index | Cafe con Leche

Copyright 2001 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified April 6, 2001