I wrote an XML parser that works great to fit my needs, but I can't retrieve the root attribute nodes no matter what I try!
So far I have the following code that works great to retrieve the child tag values:
import xml.dom.minidom def parse(filename): xmlDoc = xml.dom.minidom.parse(filename) tag = xmlDoc.getElementsByTagName('date_time').childNodes.nodeValue return tag
Here is the XML data I'm parsing:
<?xml version="1.0"?> <order type="buy" subtype="limit" orderID="7659"> <date_time>03:23:2012:11:50.35</date_time> <userID>Miss.Wanda.Sleeplate</userID> <stock_symbol>BROK</stock_symbol> <shares_ammount>50</shares_ammount> <limit>23.87</limit> </order>
What I'm trying to get is the value of the attributes of the root order tag (type, subtype, orderID)
node = tag.attributes['type'].value print node
Any help would be appreciated, thanks! :D