Do you really mean that you have an HTML structure and want one XPath expression for each element?
This smells of homework to me because constructing an XPath expression if you have the path to an element is trivial:
<myml>
<foo>
<bar id="1" />
<bar id="2" />
</foo>
</myml>
To get the xpath expression for each element, you concatenate all parent tags of each elements with /, and add the index of each element as the :nth-child axis.
Generating such an XPath expression does not help you much, which is why I think this is homework. But if this is not homework, maybe you can explain what actual problem you're trying to solve. |