[
Lists Home |
Date Index |
Thread Index
]
At 5:39 PM -0800 1/7/02, Ronald Bourret wrote:
>Maybe I haven't been reading this thread (or the DOM spec) closely
>enough. Is this saying that DOM 2 doesn't automatically insert namespace
>declarations as needed? That is, users have to add xmlns attributes by
>hand?
>
Correct, DOM does not do that. When creating an element in the
http://www.foo.com/ namespace, DOM2 does not add an
xmlns="http://www.foo.com/" in the right place to make this work.
Section 1.1.8 states:
As far as the DOM is concerned, special attributes used for declaring
XML namespaces are still exposed and can be manipulated just like any
other attribute. However, nodes are permanently bound to namespace
URIs as they get created. Consequently, moving a node within a
document, using the DOM, in no case results in a change of its
namespace prefix or namespace URI. Similarly, creating a node with a
namespace prefix and namespace URI, or changing the namespace prefix
of a node, does not result in any addition, removal, or modification
of any special attributes for declaring the appropriate XML
namespaces. Namespace validation is not enforced; the DOM application
is responsible. In particular, since the mapping between prefixes and
namespace URIs is not enforced, in general, the resulting document
cannot be serialized naively. For example, applications may have to
declare every namespace in use when serializing a document.
In other words, what should happen is that any code that moves DOM to
some other model such as SAX, XPath, or a text file should insert the
necessary namespace declarations. What actually does happen though,
is that such code often neglects to insert them, thus requiring users
to add the attributes in DOM manually. This is a big honking mess.
It gets even nastier when you consider the possibility of namespaces
being in scope on things other than element and attribute names,
since DOM really can't keep track of these at all.
--
+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo@metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| The XML Bible, 2nd Edition (Hungry Minds, 2001) |
| http://www.ibiblio.org/xml/books/bible2/ |
| http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/ |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.ibiblio.org/xml/ |
+----------------------------------+---------------------------------+
|