Re: [xml] XPath "//namespace::*" and xml: weirdness



On Tue, Mar 14, 2006 at 05:19:09PM -0500, Jason Viers wrote:
Daniel Veillard wrote:
Read the spec, then raise an issue iif you think libxml2 behaviour
deviates from the spec, thanks.
 

I wasn't questioning libxml's behavior at all, just inquiring about the 
details of the implementation. 

  Ah, okay that wasn't clear... I misunderstood and though it was about
the fact of returning the sname namespace so many times (which is a 
surprizing behaviour forced by XPath). Sorry about that...

Digging in the source found me the 
answer to my question (reproduced here to hopefully help those of later 
generations encountering the same problem).

My example returned 3 different xmlNs structs, all for the xml 
namespace.  Where did those come from?  Are the referenced in the tree 
somewhere?  All the nodes have null nsDef fields, the doc's oldNs field 
is null.

  The namespace model of XPath is the main point of divergence from the
internal libxml2 model. That's the only exception where nodes returned in
a nodeset may not come from the document but are allocated dynamically
for that nodeset.

Looking at xmlXPathFreeNodeSet in xpath.c verifies that those xmlNs 
structs were instantiated just for those XPath results (as each struct's 
"next" pointer points to the element it "came" from), as they're 
destroyed when the xmlXPathObject is freed.

  yes,.

Definite implications for wanting to keep the pointers from the 
xmlXPathObject around after it was closed. :)

  In general the lifetime of the pointers from the node set are
the ones from the document *except* for this nasty case where the models
don't match. You must be cautious in that case. In practice the namespace
axis isn't used much, precisely because it doesn't match very well the
usual tree representations I guess.

Daniel

-- 
Daniel Veillard      | Red Hat http://redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]