How to match nested italic font tags with Xpath?
<p>Consider an <code>xml</code> structure like the following</p>

<pre><code>&lt;p class="long"&gt;
  &lt;i&gt;Malicious&lt;/i&gt;
  " is the adjective based on the noun "
  &lt;i&gt;malice&lt;/i&gt;
  ", which means the desire to harm others. Both words come from the latin word "
&lt;/p&gt;
</code></pre>

<p>I want to select all text inside the <code>&lt;p&gt;</code> tag.
I tried with </p>

<pre><code>examples = tree.xpath('//p[@class="long"]/text()')
</code></pre>

<p>With this, however, all text between <code>&lt;i&gt;</code> tags is ignored for some reason.</p>

<p>What is the correct way to extract all the text inside the <code>&lt;p&gt;</code> tags, regardless of it being also contained in other nested tags?</p>

<p>Avoid the use of text() unless you have very special requirements - for exactly this reason. You're probably interested in the string value of the <code>p</code> element, not in its child text and element nodes. Exactly how to select this depends on the environment (does your XPath API allow returning a string rather than a node-set? Does it support XPath 2.0? Does your path expression select more than one "p" element? Can you just return the <code>p</code> element, and then get its string value in the host application?)</p>

python xpath lxml