W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2001

Re: [Moderator Action] How can I know declared namespaces in DOM node.

From: Philippe Le Hegaret <plh@w3.org>
Date: Mon, 10 Dec 2001 11:35:08 -0500
Message-ID: <3C14E43C.CF99435A@w3.org>
To: Yuriy <yuriy@maas.de>
Cc: www-dom@w3.org
Yuriy wrote:
> I have a little question. I parse XML document with Xerces 1.4.3. This
> document uses namespaces. Then I want to add new child org.w3c.dom.Element X
> to some org.w3c.dom.Element Y in DOM tree. Of course, I can declare in X its
> namespace, assign a prefix to this namespace and qualify X and its attributes
> with this prefix. But very often Y declares namespace, required for
> X. Moreover, this namespace is default namespace of Y. So why should I do
> unnecessary declaration of namespace in X?

You don't have to declare the namespace in X, you just need to use it to create
X. 

> Namespaces required for X is already visible inside Y. Now the question is:
> 
> 
> 
> how can I know what namespaces are visible in org.w3c.dom.Element Y,

Namspaces declaration are visible in the element X but the DOM does not rely on
them for namespace resolution. 

> what are their URI and prefixes, what is URI of default namespace for Y?

Unlike the XML namespaces recommendation, there is no concept of default
namespace in the DOM. The DOM is a dynamic API, therefore an Element can be moved
in the tree withoput changing its namespace URI.

In DOM Level 3, we are adding lookup methods for namespace URIs and
prefixes. You might want to have a look at them to rely on prefixes for the
namespace resolution.

> P.S. I can't even use org.w3c.dom.getNamespaceURI(), because "This is not a
> computed value that is the result of a namespace lookup based on an
> examination of the namespace declarations in scope. It is merely the
> namespace URI given at creation time. "

Yes, once an Element is created, you cannot change its localName or
namespaceURI.

Philippe
Received on Monday, 10 December 2001 11:35:11 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:55 GMT