I\'m interested in advice/pseudocode code/explanation rather than actual implementation.
I've done a similar task once. The main idea used was that you can use indexes of the element in the xpath. For example in the following xml
xpath to the second
will be /root[1]/el[2]
(xpath indexes are 1-based). This reads as "take the first root, then take the second one from all elements with the name el". So element something
does not affect indexing of elements el
. So you can in theory create an xpath for each specific element in your xml. In practice I've accomplished this by walking the tree recursevely and remembering information about elements and their indexes along the way.
Creating xpath referencing specific attribute of the element then was just adding '/@attrName' to element's xpath.