I am creating an XML document on the fly. and I need to know the XPath of the Node I’ve just created.
I don’t see any such function like DOMNode::calculateXPath(void):string
and I am not willing to write one by my own. is there any known lite 3rd party Solution ??
I am creating an XML document on the fly. and I need to know
Share
There’s no definite XPath for given node, because XPath is a a search query. Like in google, you can find specific page using different search terms. What’s more, XPath query returning current node can (probably will) change when you modify DOM tree, so the path you can get is valid only until next tree modification is done.
You may give each of your nodes unique ID or class name (class is safer when you want to use other IDs – there can be multiple classes and only one ID). Then you can search using this class/id.
Example for tag span and class unique_1_: