title: Python 3.3: Convert XML to YAML
body: <p>I'm trying to convert XML files to YAML using Python 3.3.
  This is my code:</p>
  
  <pre><code>#! /etc/python3
  
  test_filename_input = './reference-conversions/wikipedia-example.xml'
  test_filename_output = 'wikipedia-example_xml_read-as-binary.yaml'
  
  file_object = open( test_filename_input, 'rb')
  data_in = file_object.read()
  file_object.close()
  
  from xml.dom.minidom import parseString
  document_object = parseString( data_in)
  
  import yaml
  stream = open( test_filename_output, 'w')
  yaml.dump( document_object, stream)
  stream.close()
  </code></pre>
  
  <p>As a reference I used the XML-file from <a href="http://en.wikipedia.org/w/index.php?title=JSON&amp;oldid=622373984#XML_samples" rel="nofollow">here</a>:</p>
  
  <pre><code>&lt;person&gt;
    &lt;firstName&gt;John&lt;/firstName&gt;
    &lt;lastName&gt;Smith&lt;/lastName&gt;
    &lt;age&gt;25&lt;/age&gt;
    &lt;address&gt;
      &lt;streetAddress&gt;21 2nd Street&lt;/streetAddress&gt;
      &lt;city&gt;New York&lt;/city&gt;
      &lt;state&gt;NY&lt;/state&gt;
      &lt;postalCode&gt;10021&lt;/postalCode&gt;
    &lt;/address&gt;
    &lt;phoneNumbers&gt;
      &lt;phoneNumber type="home"&gt;212 555-1234&lt;/phoneNumber&gt;
      &lt;phoneNumber type="fax"&gt;646 555-4567&lt;/phoneNumber&gt;
    &lt;/phoneNumbers&gt;
    &lt;gender&gt;
      &lt;type&gt;male&lt;/type&gt;
    &lt;/gender&gt;
  &lt;/person&gt;
  </code></pre>
  
  <p>which should result in something like this:</p>
  
  <pre><code>---
    firstName: John
    lastName: Smith
    age: 25
    address: 
          streetAddress: 21 2nd Street
          city: New York
          state: NY
          postalCode: 10021
  
    phoneNumber: 
          -  
              type: home
              number: 212 555-1234
          -  
              type: fax
              number: 646 555-4567
    gender: 
          type: male
  </code></pre>
  
  <p>However, the result is:</p>
  
  <pre><code>&amp;id001 !!python/object/new:xml.dom.minidom.Document
  state: !!python/tuple
  - implementation: !!python/object:xml.dom.minidom.DOMImplementation {}
  - _elem_info: {}
    _id_cache: {}
    _id_search_stack: null
    childNodes: !!python/object/new:xml.dom.minicompat.NodeList
      listitems:
      - &amp;id039 !!python/object/new:xml.dom.minidom.Element
        state: !!python/tuple
        - null
        - _attrs: null
          _attrsNS: null
          childNodes: !!python/object/new:xml.dom.minicompat.NodeList
            listitems:
            - &amp;id045 !!python/object/new:xml.dom.minidom.Text
              state: !!python/tuple
              - null
              - _data: "\n  "
                nextSibling: &amp;id002 !!python/object/new:xml.dom.minidom.Element
                  state: !!python/tuple
                  - null
                  - _attrs: null
                    _attrsNS: null
                    childNodes: !!python/object/new:xml.dom.minicompat.NodeList
                      listitems:
  [...]
  </code></pre>
  
  <p>Any idea, how to get PyYAML filter out the object-stuff from xml.dom.minidom or any alternative to using xml.dom.minidom?</p>
  
  <p>Thanks!</p>