Namespaces
An important addition to DOM Level 2 not yet
discussed is DOM’s support for XML namespaces.
You’ll remember from Chapter 3 and
Chapter 4, that SAX 2.0 added
namespace support, and the same is true
for the second iteration of DOM. The key here is two new methods on
the Node interface: getPrefix( )
and
getNamespaceURI( )
. Additionally, all of the
creation methods have namespace-aware
versions available. So, instead of calling createElement( ), you call createElementNS( ).
In each of these new namespace-aware methods, the first argument is
the namespace URI, and the second is the
qualified name of the element, attribute, etc.
Note that I said qualified; this means that if you want to use a
namespace URI of “http://www.oreilly.com” and a prefix of
“ora” on an element called “copyright”, you
would call createElementNS("http://www.oreilly.com", "ora:copyright"). This is very ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access