Get data from XML file Python
<pre><code>&lt;Fruits&gt;
    &lt;Fruit&gt;
        &lt;Family&gt;Citrus&lt;/Family&gt;
        &lt;Explanation&gt;this is a Citrus fruit.&lt;/Explanation&gt;
        &lt;Type&gt;Orange&lt;/Type&gt;
        &lt;Type&gt;Lemon&lt;/Type&gt;
    &lt;/Fruit&gt;
&lt;/Fruits&gt;
</code></pre>

<p>I want to extract the Explanation of this XML code and assign it to both fruits(Type) next to them. This is my code:</p>

<pre><code>import os
from xml.etree import ElementTree
file_name = "example.xml"
full_file = os.path.abspath(os.path.join("xml", file_name))
dom = ElementTree.parse(full_file)
Fruit = dom.findall("Fruit")

for f in Fruit:
    Type = f.find("Type").text
    Explanation = f.find("Explanation").text

    print (Type, Explanation)
</code></pre>

<p>I am just getting the result for the first fruit of the tree structure. </p>

<pre><code>Orange, this is a Citrus fruit.
</code></pre>

<p>But I would like to get all types with their explanation assigned next to it. Therefore the result should look like this:</p>

<pre><code>Orange, this is a Citrus fruit.
Lemon, this is a Citrus fruit.
</code></pre>