title: Getting list of tags from Python minidom XML
body: <p>I have a fairly simple XML structure that has a certain degree of variability, so I'd like to simplify writing my parser for it.  Right now the xml looks similar to this:</p>
  
  <pre><code>&lt;items&gt;
      &lt;item&gt;
          &lt;Tag1&gt;Some Value&lt;/Tag1&gt;
          &lt;Tag2&gt;Some Value&lt;/Tag1&gt;
          &lt;Tag3&gt;Some Value&lt;/Tag1&gt;
      &lt;/item&gt;
  &lt;/items&gt;
  </code></pre>
  
  <p>I've figured out how to properly get "Some Value" out of the tags and into my data dict, but I don't necessarily know all of the tags before hand that may or may not be present.  I'd like to iterate over everything in the item class and grab the tag as a value, and the value a separate value.  </p>
  
  <p>Right now my code looks like this:</p>
  
  <pre><code>from xml.dom import minidom
  from collections import defaultdict
  
  project = defaultdict(list)
  
  xml_file = minidom.parse(sys.argv[1])
  
  
  for value in xml_file.getElementsByTagName("Tag1"):
      project['Tag1'].append(xml_file.getElementsByTagName("Tag1")[0].firstChild.data)
  for value in xml_file.getElementsByTagName("Tag2"):
      project['Tag2'].append(xml_file.getElementsByTagName("Tag2")[0].firstChild.data)
  
  print project.items()
  </code></pre>
  
  <p>The reason for the "for value" loops is because I may have tags multiple times in this context and I want all of them.  I'd love to have something like </p>
  
  <pre><code>for tag in item:
      for value in xml_file.getElementsByTagName(tag):
          project[tag].append(xml_file.getElementsByTagName(tag)[0].firstChild.data)
  </code></pre>
  
  <p>That way if I have 40 different tags I a) don't have to write 80 lines of code (laziness) and b) can handle dynamic output in the translator if the XML adds/subtracts tags in the future as I don't control the source but I know what it is capable of.</p>