Is it possible to get whole xpath through powershell if we pass select all attribute with the given name?
My xml file has an attribute named lang. I use to find the attribute value by //@lang.
If i can get full xpath [ like /root/child/@attribute ) it will avoid confusion.
No.
.NET has no “given a node, create an XPath expression” function. While in theory this is easy (iterate to parents, getting the cardinal number of the sibling at each level to create
/node[n]/node[n]/...) in practice such XPath expressions are useless because they are tied to the specific document.Another document of matching schema is likely to have a different number of children at each level and maybe different ordering; such an XPath will not find the equivalent node.
Consider:
and
the expression
/root/child1[1]/@attr1generated from the first document will find a different – albeit similar – node in the second.