Re: [xml] Namespace Nodes in XPath Nodesets & Deleting NsNodes



On Sat, Nov 06, 2010 at 08:55:11PM +0000, Noam Postavsky wrote:
Hi,

I'm investigating an xmlstarlet bug when deleting namespace nodes.
Currently deletion is implemented by calling xmlUnlinkNode() on every
node in the nodeset returned from an XPath query. This doesn't work
for namespace nodes because the nodeset holds a pointer to a duplicate
instead of the original:

/**
 * xmlXPathNodeSetDupNs:

 * Namespace node in libxml don't match the XPath semantic. In a node set
 * the namespace nodes are duplicated and the next pointer is set to the
 * parent node in the XPath semantic.

So I'd appreciate if someone could point me to or provide an
explanation as to why namespace nodes are treated specially. Also, any
advice on how to go about deleting namespace nodes.

  Okay, in libxml2 tree, namespace nodes are only represented as
namespace nodes definitions, i.e. NsDef nodes carried by the ellement
where the xmlns definition is done. This is different from namespace
nodes in XPath where they are present on all the nodes where they
are in scope.
  If you want to change namespaces in libxml2 tree you can't search them
with XPath namespace:: axis, those nodes are created on the fly to match
the namespace node semantic of XPath and destroyed when the XPath
nodeset is freed. To destroy namespaces in the tree you need to search
the NsDef where it is carried, and in the full tree in scope remove
any reference from elements or attributes.

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/



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