Re: [xml] obtaining an XPath expression given a node ptr



On Fri, Nov 09, 2001 at 04:13:40PM -0700, Vakoc, Mark wrote:

given an xmlNodePtr in a document, is it possible to retrieve a xpath
expression that uniquely identifies that node?

i.e. a given document

<?xml version="1.0"?>
<root>
  <a/>
  <a><b/><b><c/></b></a>
</root>

And you had the xmlNodePtr to node 'C', you would receive back an xpath
expression of "/root/a[2]/b[2]/c"

  The function xmlShellPwd() which implements the 'pwd' command in shell
mode does that, but is not properly isolated and sometimes seems to put
an extra leading / . it may not work well for non-element nodes too.

  This function should be cleaned up and isolated with a proper interface
and then exported. Should be like 20mn of work, patch welcome ...

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.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]