Christian Stocker shares in this new blog post about an update he's made to the DOM functionality in PHP - adding the getNodePath feature.
With this, you can easily get an XPath for any given DOMNode, works also for attributes, text nodes, comments and all other node types. It's basically just a simple wrapper for xmlGetNodePath from libxml2, maybe useful for some other people also.
He gives a code example and notes that more information about XML functionality improvements will be coming from his blog soon.