[DAS2] XML namespaces

Andrew Dalke dalke at dalkescientific.com
Wed Mar 15 15:05:52 UTC 2006


I mentioned this yesterday but am doing it again as its own email.
This is a quick tutorial on XML namespaces.

The DAS spec uses XML namespaces.  XML didn't start with namespaces.
They were added later.  Older parsers, like SAX 1.0, did not understand
namespaces.  Newer ones, like SAX 2.0, do.

By default a document does not have a namespace.  For example,

<person name="Andrew" />

has no namespace.

To declare a default namespace use the 'xmlns' attribute.  All
attributes which start 'xml' or are in the 'xml:' namespace are
reserved.

<person name="Andrew" xmlns="http://www.biodas.org/" />

This is the name 'person' in the namespace 'http://www.biodas.org/'.
The namespace is an opaque identifer.  It leverages URIs in part
because it's much easier to guarantee uniqueness.

The combination of (namespace, tag name) is unique.  The tag
name is also called the "local name".

That's to distinguish it from a "qualified name", also called
a "qname".  These look like

<abc:person name="Andrew" xmlns:abc="http://www.biodas.org/" />

This element has identical meaning to the previous element
using the default namespace.  It's qname is 'abc:person' but
the full name is the tuple of

    ("http://www.biodas.org/", "person")

For notational convenience this is sometimes written in Clark
notation, as
   {http://www.biodas.org}person

   Element                                     Clark notation
<person />                                      person
<person xmlns="" />                             {}person
                            ("empty namespace" is different than "no  
namespace")

<person xmlns="http://biodas.org/" />            
{http://biodas.org/}person
<das:person xmlns:das="http://biodas.org/" />    
{http://biodas.org/}person
<X:person xmlns:X="http://biodas.org/" />        
{http://biodas.org/}person

The prefix used doesn't matter.  Only the combination of
   (namespace, local name)
is important.  The Clark notation string captures that as a single  
string,
which is much easier when doing comparisons.

For example, if you try the dasypus verifier at
    
http://cgi.biodas.org:8080/verify?url=http://das.biopackages.net/das/ 
genome/yeast/S228C/feature?inside=chr1/0:1000&doctype=features

one of the output messages is

Expected element '{http://www.biodas.org/ns/das/genome/2.00}FEATURES'  
but
got '{http://www.biodas.org/ns/das/2.00}FEATURELIST' at byte 113, line  
3, column 2

This shows the Clark name for the elements, indicating that the root
element has a different namespace and local name from what Dasypus  
expects.

					Andrew
					dalke at dalkescientific.com




More information about the DAS2 mailing list