I have a XML file with a structure similar to this
<records>
<record something="this" name="ABC"/>
<record something="this" name="DEF"/>
<record name="ABC" something="this"/>
<record name="GHI" something="this"/>
<record something="this" name="ABC/>
What I am looking for is a Python script to bring back all unique attribute values with the attribute name of name i.e.
ABC
DEF
GHI
The script runs fine when I put the filename in myself but when it is passed through as a parameter, it falls over.
from xml.dom import minidom
import sys
print sys.argv[1]
xmldoc = minidom.parse('/root/%s.xml' % sys.argv[1])
itemlist = list(xmldoc.getElementsByTagName('record'))
itemlist.sort()
for s in itemlist :
if s.hasAttribute("name"):
print s.attributes['name'].value
However it is still not bring back unique values