0

XML Python

Hello, I need to know how to get an attribute of an xml child node with python. The xml looks something like this: <?xml version="1.0"?> http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> true . . . . You would need to get the data associated with Ref, Date and PORef; but I can't get it out

18th May 2020, 2:33 PM
David Chichon Sanchez
David Chichon Sanchez - avatar
2 Answers
0
Check the xml module in python ''' data associated with Ref, Date and PORef; ATTENTION!! https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.iter ''' import xml.etree.ElementTree as ET tree = ET.parse('example.xml') root = tree.getroot() attributes = [] search_attributes = ('Ref', 'Date', 'PORef') for elem in root: for _elem in elem: attributes.append(_elem.attrib) for i in attributes: for k, v in i.items(): if k in search_attributes: print(f'{k}:{v}')
20th May 2020, 6:16 PM
Emanuel Maliaño
Emanuel Maliaño - avatar
0
I hope it will help you
21st May 2020, 1:19 AM
Emanuel Maliaño
Emanuel Maliaño - avatar