Re: XPath namespace nodes

Gareth Reakes wrote:

>Hi,
>	I'm implementing the Level 3 XPath module and have a query. I 
>understand that namepsace nodes are created at parse time and are not 
>affected by changes to the tree. What happens when we create a new element 
>in a certain namespace? Do we also create namespace nodes if appropriate? 
>If so then it seems that we are saying its not just a parse time thing. If 
>not then a query such as
>
>/root/newEle/namespace::*
>
>
>would return a different result if we serialised the document (after 
>namespace normalisation) and then reparsed it. 
>  
>
XPath 1.0 could claim that these occur at parse time, but often in DOM 
there was no parsing, and now in XPath 2.0, they may not go through 
parsing.  I believe that there are problems in XPath 2.0 data model with 
the concept that namespace nodes are created at element creation time, 
which I have pointed out in previous comments to that working group, but 
they have not been addressed.

DOM Namespace nodes are clearly NOT created when the DOM element is 
created.  It is impossible and inefficient to do so, because which 
namespace nodes are in-scope changes with where the element is inserted 
and many other things that have not occurred yet at element creation 
time such as insertion into the tree and adding namespace attributes to 
the element.

For this reason, it is expected that implementations will create 
namespace nodes in response to a query.  The DOM XPath API makes it 
clear, I think, that these are identified created during query 
evaluation from the namespace information available in the tree and then 
just forgotten until next time they are requested, when they are 
recreated.  If an application were to hold on to the namespace returned 
from one of the previous queries and then later to remove the element 
from a scope which declared the namespace, the namespace node does not 
mutate, not even to null-out it's parent.

Ray Whitmer
rayw@netscape.com

Received on Friday, 13 September 2002 13:25:43 UTC