In the lxml-faq I read:<br><br><div class="section" id="general-questions"><div class="section" id="how-can-i-map-an-xml-tree-into-a-dict-of-dicts"><h2>How can I map an XML tree into a dict of dicts?</h2>
<p>I'm glad you asked.</p>
<div class="syntax"><pre><span class="k">def</span> <span class="nf">recursive_dict</span><span class="p">(</span><span class="n">element</span><span class="p">):</span><br>     <span class="k">return</span> <span class="n">element</span><span class="o">.</span><span class="n">tag</span><span class="p">,</span> \<br>
            <span class="nb">dict</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">recursive_dict</span><span class="p">,</span> <span class="n">element</span><span class="p">))</span> <span class="ow">or</span> <span class="n">element</span><span class="o">.</span><span class="n">text</span><br>
<br>However this does not work where you have xml-elements where there are more than one child on the same level.  For example:<br><br><keywords count="4"><br><keyword>Bayesian nonparametric statistics</keyword><br>
<keyword>Frailty modeling</keyword><br><keyword>Poly urn sampling</keyword><br><keyword>Proportional hazards model</keyword><br></keywords><br><br>results in <br><br>>>> alys[100]['item']['keywords']<br>
{'keyword': 'Proportional hazards model'}<br></pre></div>
</div>
</div>How do I get it to give me the following result?<br><br>{'keywords': [<br>{'keyword': 'Bayesian nonparametric statistics'},<br>{'keyword': 'Frailty modeling'},<br>{'keyword': 'Poly urn sampling'},<br>
{'keyword': 'Proportional hazards model'}<br>]}<br clear="all"><br>Regards<br>Johann<br>-- <br> May grace and peace be yours in abundance through the full knowledge of God and of Jesus our Lord!  His divine power has given us everything we need for life and godliness through the full knowledge of the one who called us by his own glory and excellence. <br>
                                                    2 Pet. 1:2b,3a<br><br>