title: How to create nested dictionary from XML using python?
body: <p>I am reading an XML file and take part of it and write it to YAML file.
  For example, in this xml file,</p>
  <pre><code>&lt;project&gt;
  
  
    &lt;scm class=&quot;hudson.scm.NullSCM&quot;/&gt;
    &lt;assignedNode&gt;python&lt;/assignedNode&gt;
    &lt;canRoam&gt;false&lt;/canRoam&gt;
    &lt;disabled&gt;false&lt;/disabled&gt;
    &lt;blockBuildWhenDownstreamBuilding&gt;false&lt;/blockBuildWhenDownstreamBuilding&gt;
    &lt;blockBuildWhenUpstreamBuilding&gt;false&lt;/blockBuildWhenUpstreamBuilding&gt;
    &lt;triggers&gt;
      &lt;hudson.triggers.TimerTrigger&gt;
        &lt;spec&gt;H * * * *&lt;/spec&gt;
      &lt;/hudson.triggers.TimerTrigger&gt;
    &lt;/triggers&gt;
    &lt;concurrentBuild&gt;false&lt;/concurrentBuild&gt;
    &lt;builders&gt;
  </code></pre>
  <p>I want to read only the disabled value and the spec value and write it to a YAML file like this:
  Expected output:</p>
  <pre><code>disabled: 'false'
  name: Cancellation_CMT_Tickets
  triggers:
    hudson.triggers.TimerTrigger:
      spec: H * * * *
  </code></pre>
  <p>Only when my resultant dictionary is in this format</p>
  <pre><code>d = {&quot;trigger&quot;:{&quot;hudson.triggers.TimerTrigger&quot;: {&quot;spec&quot;: &quot;H * * * *&quot;}}}
  </code></pre>
  <p>I can dump that into yaml file with the above format. MY current code looks like this, search key is passed as runtime arguments</p>
  <pre><code>import os, xml.etree.ElementTree as ET
  import yaml,sys
  tree = ET.parse('test.xml')
  root = tree.getroot()
  
  d = {}
  def xmpparse(root,searchkey):
      for child in root:
          if child.tag == searchkey:
              d[child.tag]=child.text
          elif len(child):
             xmpparse(child,searchkey)
  for i in sys.argv:
      xmpparse(root,i)
  
  print(yaml.dump(d, default_flow_style=False))
  </code></pre>
  <p>Current output:</p>
  <pre><code>disabled: 'false'
  spec: H * * * *
  </code></pre>
  <p>Any help would be much appreciated. Thanks in advance!</p>