Using xml.dom.minidom , you can extract tag data using method doc.getElements ByTagName() and reading attribute firstChid.data. Note that "root" has no data.
[code=Python]from xml.dom import minidom
def getTagData(doc, tag):
output = []
for elem in doc.getElements ByTagName(tag):
data = str(elem.firstC hild.data).stri p()
if data:
output.append(d ata)
return output
for tag in ('root', 'weapon', 'price'):
data = getTagData(docX ML,tag)
if data:
for item in getTagData(docX ML,tag):
print "Tag '%s': %s" % (tag, item)
else:
print "No data to display for tag '%s'" % tag[/code]
Output:[code=Python]>>> No data to display for tag 'root'
Tag 'weapon': P228
Tag 'weapon': USP
Tag 'price': 468
Tag 'price': 500
>>> [/code]
Comment