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
1from lxml import etree
2doc = etree.parse(filename)
3
4memoryElem = doc.find('memory')
5print memoryElem.text # element text
6print memoryElem.get('unit') # attribute
7
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