You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Scott Cantor <ca...@osu.edu> on 2006/03/03 09:25:28 UTC

Behavior of DOM3 lookupNamespaceURI()

I don't think is a bug, but it's decidedly odd behavior, in my opinion, at
least based on a lot of obvious uses for the method. I'm sure it's not a bug
in fact, because the code is directly from the DOM3 spec, which says to
implement lookupNamespaceURI such that no namespace declaration has to be
present in the DOM in order for the function to return a result for a given
prefix. Namely if some element at or above the node is assigned a prefix and
a namespace, it will match it and return that namespace.

So I have a non-wellformed document, but the lookup function is telling me
that the prefix is "bound" to that namespace. This seems off to me.

Example:

DOMElement e: <ns:foo> where the NamespaceURI is http://foo.com

e->lookupNamespaceURI("ns") returns "http://foo.com"

I would have intuitively expected the element to have to look like:

<ns:foo xmlns:ns="http://foo.com">

So, what am I missing? What good is the method if by XML processing rules
the prefix isn't actually going to be valid when I serialize the document?

-- Scott


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


RE: Behavior of DOM3 lookupNamespaceURI()

Posted by Alberto Massari <am...@datadirect.com>.
Hi Scott,

At 10:48 AM 3/3/2006 -0500, Scott Cantor wrote:
> > The DOM is allowed to be in a state where there is no xmlns:ns=""
> > namespace declaration and "ns" is used as the prefix of an element or
> > attribute; the serialization code will handle this case by adding the
> > declaration on the fly (and renaming conflicting prefixes if bound to
> > different URIs in the same scope).
>
>*Some* serialization code will do this. Some will not.

I am talking about the DOML3 serializer code.

>None of them will
>help me deal with signatures effectively, so relying on the behavior of a
>serializer is not really an option in my case.
>
>I guess what you're saying is that the DOM3 methods are really not general
>purpose, but are intended to be used in conjunction with the DOMLS
>serializer.

I am simply adapting to the behavior of DOM: read the chapter 1.3.3 
of the specs

"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. "

Alberto


>What seems odd to me is that in effect, the DOMLS code can't rely on these
>methods to know when to declare namespaces. That seems kind of strange.
>
>Anyway, I understand that it's intentional behavior, so I'll write my own.
>
>-- Scott
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
>For additional commands, e-mail: c-dev-help@xerces.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


RE: Behavior of DOM3 lookupNamespaceURI()

Posted by Scott Cantor <ca...@osu.edu>.
> The DOM is allowed to be in a state where there is no xmlns:ns="" 
> namespace declaration and "ns" is used as the prefix of an element or 
> attribute; the serialization code will handle this case by adding the 
> declaration on the fly (and renaming conflicting prefixes if bound to 
> different URIs in the same scope).

*Some* serialization code will do this. Some will not. None of them will
help me deal with signatures effectively, so relying on the behavior of a
serializer is not really an option in my case.

I guess what you're saying is that the DOM3 methods are really not general
purpose, but are intended to be used in conjunction with the DOMLS
serializer.

What seems odd to me is that in effect, the DOMLS code can't rely on these
methods to know when to declare namespaces. That seems kind of strange.

Anyway, I understand that it's intentional behavior, so I'll write my own.

-- Scott


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: Behavior of DOM3 lookupNamespaceURI()

Posted by Alberto Massari <am...@datadirect.com>.
Hi Scott,

At 03:25 AM 3/3/2006 -0500, Scott Cantor wrote:
>I don't think is a bug, but it's decidedly odd behavior, in my opinion, at
>least based on a lot of obvious uses for the method. I'm sure it's not a bug
>in fact, because the code is directly from the DOM3 spec, which says to
>implement lookupNamespaceURI such that no namespace declaration has to be
>present in the DOM in order for the function to return a result for a given
>prefix. Namely if some element at or above the node is assigned a prefix and
>a namespace, it will match it and return that namespace.
>
>So I have a non-wellformed document, but the lookup function is telling me
>that the prefix is "bound" to that namespace. This seems off to me.
>
>Example:
>
>DOMElement e: <ns:foo> where the NamespaceURI is http://foo.com
>
>e->lookupNamespaceURI("ns") returns "http://foo.com"
>
>I would have intuitively expected the element to have to look like:
>
><ns:foo xmlns:ns="http://foo.com">
>
>So, what am I missing? What good is the method if by XML processing rules
>the prefix isn't actually going to be valid when I serialize the document?

The DOM is allowed to be in a state where there is no xmlns:ns="" 
namespace declaration and "ns" is used as the prefix of an element or 
attribute; the serialization code will handle this case by adding the 
declaration on the fly (and renaming conflicting prefixes if bound to 
different URIs in the same scope).

Hope this helps,
Alberto


>-- Scott
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
>For additional commands, e-mail: c-dev-help@xerces.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org