extracts attribute python xml

Solutions on MaxInterview for extracts attribute python xml by the best coders in the world

showing results for - "extracts attribute python xml"
Elizabeth
31 Jan 2020
1from xml.dom import minidom
2xmldoc = minidom.parse('items.xml')
3itemlist = xmldoc.getElementsByTagName('item') 
4print "Len : ", len(itemlist)
5print "Attribute Name : ", itemlist[0].attributes['name'].value
6print "Text : ", itemlist[0].firstChild.nodeValue
7for s in itemlist :
8    print "Attribute Name : ", s.attributes['name'].value
9    print "Text : ", s.firstChild.nodeValue
10
Albin
22 Apr 2019
1from lxml import etree
2doc = etree.parse(filename)
3
4memoryElem = doc.find('memory')
5print memoryElem.text        # element text
6print memoryElem.get('unit') # attribute
7
Alya
30 Feb 2018
1import xml.dom.minidom as minidom
2doc = minidom.parse(filename)
3
4memoryElem = doc.getElementsByTagName('memory')[0]
5print ''.join( [node.data for node in memoryElem.childNodes] )
6print memoryElem.getAttribute('unit')
7
similar questions
queries leading to this page
extracts attribute python xml