Iterate through xml to find url with specific extension with python

crazy_demon09

New Member
I have an xml file that I download from a url. I would then like to iterate through the xml to find the link to a file with a specific file extension.My xml looks something like this:\[code\]<Foo> <bar> <file url="http://foo.txt"/> <file url="http://bar.doc"/> </bar></Foo>\[/code\]I've written code to get the xml file like this:\[code\]import urllib2, refrom xml.dom.minidom import parseStringfile = urllib2.urlopen('http://foobar.xml')data = http://stackoverflow.com/questions/11422647/file.read()file.close()dom = parseString(data)xmlTag = dom.getElementsByTagName('file')\[/code\]And then I'd 'like' to get somthing like this to work:\[code\] i=0 url = '' while( i < len(xmlTag)): if re.search('*.txt', xmlTag.toxml() ) is not None: url = xmlTag.toxml() i = i + 1;** Some code that parses out the url **\[/code\]But that throws an error. Anyone have tips on a better approach?Thanks!
 
Back
Top