Dump All XPaths
<p>Does lxml or exml have a function to export all xpaths in an XML?</p>

<p>XML Example:</p>

<pre><code> &lt;note&gt;
    &lt;to&gt;Tove&lt;/to&gt;
    &lt;from&gt;Jani&lt;/from&gt;
    &lt;heading&gt;Reminder&lt;/heading&gt;
    &lt;body&gt;
         &lt;content&gt;Don't forget me this weekend!&lt;/content&gt;
    &lt;/body&gt;
    &lt;/note&gt;
</code></pre>

<p>XPath Results:</p>

<pre><code>\\note
\\note\to
\\note\from
\\note\heading
\\note\body
\\note\body\content
</code></pre>

<p>You have to iterate over the tree and call <a href="http://lxml.de/api/lxml.etree._ElementTree-class.html#getpath" rel="nofollow">getpath</a> on each node:</p>

<pre><code>x = """&lt;note&gt;
    &lt;to&gt;Tove&lt;/to&gt;
    &lt;from&gt;Jani&lt;/from&gt;
    &lt;heading&gt;Reminder&lt;/heading&gt;
    &lt;body&gt;
         &lt;content&gt;Don't forget me this weekend!&lt;/content&gt;
    &lt;/body&gt;
    &lt;/note&gt;"""

from lxml import etree
from StringIO import StringIO
tree = etree.parse(StringIO(x))

paths = "\n".join(tree.getpath(n) for n in tree.iter())
print(paths)
</code></pre>

<p>Output:</p>

<pre><code>/note
/note/to
/note/from
/note/heading
/note/body
/note/body/content
</code></pre>

python xml xpath