I have a very big xml with a lot of people,with each person having a unique id stored in a attribute in his xml node, my question is how do i store only the desire attribute(the first one in this case) of the node, not all attributes, so far my code is:
if os.path.isfile('library.xml'):
xml = ET.parse('library.xml')
root = xml.getroot()
create_file = 'coverage.xml'
openfile = open(create_file, 'a')
openfile.write('<?xml version="1.0" encoding="ISO-8859-1"?>')
for child in root:
for analyst in child:
analystId = []
analystId.append(analyst.attrib) #<- Trying to append only first one as a dictionary with [1], analystId.append(analyst.attrib[1]), but it didn't work
print str(analystId)
openfile.close()
else:
print "Library xml not found in " + str(search_path) + ". Please check if file exist."
So as far as it goes,now it takes all the attributes and store them in the analystId, thou I need only the first one(in this case).
No comments:
Post a Comment