This is actually a duplicate of this question. Although this is not marked as an answer, the method my answer to this question is the only way to uniquely formulate XPath for a node in an XML document that will always work under any circumstances. (It also works for all types of node, not just for elements.)
As you can see, the XPath that it produces is ugly and abstract. but it addresses the problems that many defendants have raised. Most of the suggestions made here create XPath, which when used to search for a source document will create a set of one or more nodes that includes the target node. This is what βor moreβ is that problem. For example, if I have an XML representation of a DataSet, the naive XPath for a particular DataRow, /DataSet1/DataTable1 , also returns the elements of all other DataRows in the DataTable. You cannot fix this without knowing how the XML forum is (for example, is there a primary key element?).
But /node()[1]/node()[4]/node()[11] there is only one node that it will ever return, no matter what.
Robert Rossney Jan 17 '09 at 1:54 2009-01-17 01:54
source share