Re: XML::LibXML XPath fails to find xmlns:xml="http://www.w3.org/XML/1998/namespace"

Emmanuel Rodriguez <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
Petr Pajas wrote:
> Hi Emmanuel, 
>
> you are right, but is it worth fixing? 
Probably not. My initial aim was to understand why there was a 
difference between the results returned by Perl and xmllint (C). Once I 
found the reason I figured that I might as well share it.
> The namespace:: axis is problematic and 
> not fully implemented even in libxml2 itself. The problem is that namespace 
> nodes are in libxml2 represented by a very simple structure (compared to 
> other nodes); unlike for instance ordinary attribute nodes, they do not know 
> their owner element (e.g. namespace::*/parent::* won't work), sibling 
> attributes, etc. 
I've noticed that by looking at the internals of XML::LibXML and libxml2.
> Also their life cycle in libxml2 is different and quite 
> complicated (a NS node can be attached to no element, yet still there may be 
> elements refering to it as their namespace). For this reason, XML::LibXML's 
> memory management is quite elementary for NS nodes compared to other nodes. 
> We currently create a copy of xmlNs struct every time we expose a namespace 
> to Perl. It is simple but safe.
>
> What libxml2 does when it needs to instantiate a NS node for the 'xml' prefix 
> is that it creates the xmlNs struct by hand (avoiding the xmlNewNs 
> constructor):
>
>         xmlNsPtr ns;
>         ns = (xmlNsPtr) xmlMalloc(sizeof(xmlNs));
>         if (ns == NULL) {
>             xmlTreeErrMemory(
>                 "allocating the XML namespace");
>             return (NULL);
>         }
>         memset(ns, 0, sizeof(xmlNs));
>         ns->type = XML_LOCAL_NAMESPACE;
>         ns->href = xmlStrdup(XML_XML_NAMESPACE);
>         ns->prefix = xmlStrdup((const xmlChar *)"xml");
>
>   
I was wondering how libxml2 was dealing with this because its XML parser 
is adding the XML namespaces to the DOM tree without problem.
> I could of course do the same, but I don't feel very comfortable adding such 
> an unencapsulated code to XML::LibXML, but I'm willing to if you insist.
>   
Based on the explanations that I have received I don't think that this 
is truly a bug. Probably no one is going to be missing the xmlns:xml 
namespace in their results.

Cheers,
Emmanuel

_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.