Hi Ben,
Ben Griffin <[email protected]> writes:
> Given a specific DOMNode, is there a method for finding (or deriving) a
> valid XPath that uniquely identifies that DOMNode?
You could go up the document tree (by calling getParentNode) and construct
the XPath path by prefixing the element names, something along these
lines (pseudo-code):
string xpath (DOMElement* n)
{
if (n == 0)
return "/";
else
return xpath (n->getParentNode ()) + "/" + n->getName ();
}
This will work for documents that don't contain sequences of elements
on the same lavel. If you have to handle this situation then you will
need to extend this logic to also include the element indexes, e.g.,
//foo/bar[2].
Boris
--
Boris Kolpackov, Code Synthesis Tools http://codesynthesis.com/~boris/blog
Open-source XML data binding for C++: http://codesynthesis.com/products/xsd
XML data binding for embedded systems: http://codesynthesis.com/products/xsde