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



On Sat, Nov 10, 2001 at 03:33:08AM -0500, Daniel Veillard wrote:
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 ...

  Okay I did it:

http://cvs.gnome.org/bonsai/cvsquery.cgi?module=gnome-xml&branch=HEAD&branchtype=match&dir=gnome-xml&file=&filetype=match&who=veillard&whotype=match&sortby=Date&hours=&date=explicit&mindate=11%2F10%2F01+05%3A07&maxdate=11%2F10%2F01+05%3A09&cvsroot=%2Fcvs%2Fgnome

  xmlChar * xmlGetNodePath(xmlNodePtr node);

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]