title: python prints document{} when try to iterate over xml and print tags and attributes
body: <p>I have an xml document that looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;?xml-stylesheet href="CoreNLP-to-HTML.xsl" type="text/xsl"?&gt;
  &lt;root&gt;
    &lt;document&gt;
      &lt;docId&gt;CVE-2002-2131.txt&lt;/docId&gt;
      &lt;sentences&gt;
        &lt;sentence id="1"&gt;
          &lt;tokens&gt;
            &lt;token id="1"&gt;
              &lt;word&gt;Directory&lt;/word&gt;
              &lt;lemma&gt;Directory&lt;/lemma&gt;
              &lt;CharacterOffsetBegin&gt;0&lt;/CharacterOffsetBegin&gt;
              &lt;CharacterOffsetEnd&gt;9&lt;/CharacterOffsetEnd&gt;
              &lt;POS&gt;NNP&lt;/POS&gt;
            &lt;/token&gt;
            &lt;token id="2"&gt;
              &lt;word&gt;traversal&lt;/word&gt;
              &lt;lemma&gt;traversal&lt;/lemma&gt;
              &lt;CharacterOffsetBegin&gt;10&lt;/CharacterOffsetBegin&gt;
              &lt;CharacterOffsetEnd&gt;19&lt;/CharacterOffsetEnd&gt;
              &lt;POS&gt;NN&lt;/POS&gt;
            &lt;/token&gt;
            &lt;token id="3"&gt;
              &lt;word&gt;vulnerability&lt;/word&gt;
              &lt;lemma&gt;vulnerability&lt;/lemma&gt;
              &lt;CharacterOffsetBegin&gt;20&lt;/CharacterOffsetBegin&gt;
              &lt;CharacterOffsetEnd&gt;33&lt;/CharacterOffsetEnd&gt;
              &lt;POS&gt;NN&lt;/POS&gt;
            &lt;/token&gt;
            &lt;token id="4"&gt;
              &lt;word&gt;in&lt;/word&gt;
              &lt;lemma&gt;in&lt;/lemma&gt;
              &lt;CharacterOffsetBegin&gt;34&lt;/CharacterOffsetBegin&gt;
              &lt;CharacterOffsetEnd&gt;36&lt;/CharacterOffsetEnd&gt;
              &lt;POS&gt;IN&lt;/POS&gt;
            &lt;/token&gt;
             ...
  </code></pre>
  
  <p>For some reason when I try to iterate over the xml and print the child tag and attribute, it's printing document {}.</p>
  
  <p>This is my code:</p>
  
  <pre><code>print("-------")
  #extract from xml file and get fields ready for csv for this document
  newFilePathOneXml=os.path.join("ners",filenameWithoutExtension,'CVE-2002-2131.txt.xml')
  print(newFilePathOneXml)
  from xml.etree import ElementTree as et
  tree = et.parse(newFilePathOneXml)
  print("here2")
  root = tree.getroot()
  print("here3")
  for child in root:
      print("here4")
      print (child.tag, child.attrib)
      print("here5")
  #f = open(newFilePathOneXml,"r")
  #print(f.read())
  et.dump(myRoot)
  </code></pre>
  
  <p>This is what gets printed:</p>
  
  <pre><code>---
  ners\nvdcve-1.1-2002\CVE-2002-2131.txt.xml
  here2
  here3
  here4
  document {}
  here5
  ...........prints xml document here................
  </code></pre>
  
  <p>I'm trying to follow instructions at this link to <a href="https://docs.python.org/2/library/xml.etree.elementtree.html" rel="nofollow noreferrer">get the xml out and access with child tags</a>.  All I really need are the tags called word in each token element.  I'm going to get the word values and write to string.</p>
  
  <p>Any idea why it's not working?  The filename is cve-2002-2131.txt.xml.</p>
  
  <p>Update: I added file read and printed file contents, and then tried et.dump(myRoot) and it does print the entire xml that way, like it did to read the file and print(f.read()).</p>
  
  <p>Update2: 
  I got this to work but I'm not sure what the best way to get the token element values is.</p>
  
  <pre><code>for elem in tree.iter():
      print (elem)
  </code></pre>
  
  <p>prints:</p>
  
  <pre><code>here3
  &lt;Element 'root' at 0x000002588AF2A5E8&gt;
  here4
  here5
  &lt;Element 'document' at 0x000002588AF2A548&gt;
  here4
  here5
  &lt;Element 'docId' at 0x000002588AF2AB88&gt;
  here4
  here5
  &lt;Element 'sentences' at 0x000002588AF89638&gt;
  here4
  here5
  &lt;Element 'sentence' at 0x000002588AF89688&gt;
  here4
  here5
  &lt;Element 'tokens' at 0x000002588AF89CC8&gt;
  here4
  here5
  &lt;Element 'token' at 0x0000025884CFAC28&gt;
  ...
  </code></pre>
  
  <p>I'm looking at <a href="https://stackoverflow.com/questions/21074361/how-to-recursively-iterate-over-xml-tags-in-python-using-elementtree">iterate over tree</a>, and there's an answer about tree.findall, but it's doing weird things.</p>
  
  <pre><code>tokens=tree.findall('.//tokens')
  print(tokens)
  #for token in range(len(tokens))  #this gives error
  #    print(token)
  </code></pre>
  
  <p>prints:</p>
  
  <pre><code>[&lt;Element 'tokens' at 0x00000222B2059CC8&gt;, &lt;Element 'tokens' at 0x00000222ABDF7958&gt;, &lt;Element 'tokens' at 0x00000222ABDFE318&gt;]
  </code></pre>