Skip to content

Getting the actual XPATH of an xml_node (xml_node::path() doesn't seem to do it...) #396

Answered by zeux
tstack asked this question in Q&A
Discussion options

You must be logged in to vote

path() predates XPath, and uses a simpler syntax that is compatible with first_element_by_path - but it indeed doesn't work when the sibling name is not unique. It's not a bug, just a limitation of the format that path() works with; maybe it's worth highlighting in the documentation / header comment, but otherwise it's by design.

Note that the general construction of the path may need to be somewhat domain-specific, for example if the path needs to survive document changes but elements have unique ids then it may be better to construct smth like /abc/def[@id = 'hi'].

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@tstack
Comment options

Answer selected by tstack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants