Trying to parse xml to text I got something like this,
INPUT FILE
<Item id="1"></Item>
<Item id="2"></Item>
<Item id="1"></Item>
<Item id="2"></Item>
CURRENT OUTPUT
Item ->1
Item ->2
Item ->2
Item ->1
My DESIRED OUTPUT would be,
Item ->1
Item ->2
(Ignoring repeated id values)
The current code I’m using to obtain my CURRENT OUTPUT is,
list = node.getElementsByTagName('Item')
for item in list:
output_id = item.getAttribute('id')
print "Item ->", output_id
I’ve tried thousands of list remove methods but they all output the double ids. Help would be greatly appreciated.
Tks
At first, every DOM parser will return doubled ids as they’re different elements.
To avoid, go through dom tree and store results in
dictobject. This will get you only last items.UPD:
And more ‘pythonic’ way: