title: Parsing XML using minidom with regex
body: <p>I am trying to parse some XML, looking for elements with the tag name "ip"  Ultimately I need a list of strings with IP addresses in them.   Here is what I have tried:</p>
  
  <pre><code>def parseHosts(xmldoc):
    hostsNode = xmldoc.firstChild
    xmlList = hostsNode.getElementsByTagName("ip")
  
    ipList = []
    for ip in xmlList:
      ipList.append(ip.childNodes[0].nodeValue)
  
    print ipList
  &gt;&gt;&gt;[u'172.16.60.92', u'172.16.60.89', u'\n              ', u'172.16.60.90', u'172.16.60.91', u'172.16.60.93']
  </code></pre>
  
  <p>That's OK.   but I need a list of strings of IP addresses...   I don't want nodes that are empty.  just a nice list of addresses like this:</p>
  
  <pre><code>['172.16.60.1', '172.16.60.5', 172.16.60.100']
  </code></pre>
  
  <p>I have tried a bit of regex with a list comprehension</p>
  
  <pre><code>  regex = re.compile(r'172\.16\.[0-9]*\.[0-9]*')
    [m.group(0) for l in ipList for m in [regex.search(1)] if m]
  </code></pre>
  
  <p>But I get the following error</p>
  
  <pre><code>File "myParser.py", line 47, in parseHosts
  [m.group(0) for l in ipList for m in [regex.search(1)] if m]
  TypeError: expected string or buffer
  </code></pre>
  
  <p>and try as I might I can not find out with type ipList is using <code>type(ipList)</code> nor can I figure out how to make this stuff a string.</p>
  
  <p>Also... getting rid of that Unicode stuff would be good.</p>
  
  <p>Clearly I have gone off the deep end here somewhere, but I am not sure where to look.</p>