Wiki  |   Blog  |   Sitemap  |   Search  
Home
HomeBlogDefault namespaces in DOM

Oh, these confusing default namespaces in DOM

Apparently some (wink!) people have troubles understanding how DOM treats default namespaces. To clarify the issue, let us consider a piece of XML parsed in an Namespaces-aware DOM implementation.

<?xml version="1.0" encoding="utf-8"?> <element1 attribute1="value1"> <elemen2 attribute2="value2" xmlns="http://mycompany.com"> <element3 attribute3="value3" xmlns="" /> </element2> </element1>

In the table below you can see what namespaces get elements and attributes:

element/attribute namespaceURI
element1 null
attribute1 null
element2 http://mycompany.com
attribute2 null
element3 null
attribute3 null
From the spec: If there is a default namespace declaration in scope, the expanded name corresponding to an unprefixed element name has the URI of the default namespace as its namespace name. If there is no default namespace declaration in scope, the namespace name has no value. The namespace name for an unprefixed attribute name always has no value.