I am new to trying to parse XML with python I have provided the xml below. I am need to get the following data Instrmt afg="AG" and Qty Typ="FIN" QTYL="149" I need the AG and the 149.
I have tried the following:
from xml.dom import minidom
xmldoc = minidom.parse(test.xml)
batch = xmldoc.getElementsByTagName('Batch')[0]
rpt = batch.getElementsByTagName('PosRpt')
for ag in rpt:
sym = ag.getElementsByTagName('Instrmt')
print(sym)
When I do this I get a DOM object and not sure how to get the results I am trying for.
- <XML r="20030517" s="20042209" v="4.4" xr="FIA" xv="1">
- <Batch>
- <PosRpt RptID="175" BizDt="2013-01-03" ReqTyp="0" >
<Pty ID="Ade" R="21" />
- <Pty ID="000" R="4">
<Sub ID="F" Typ="29" />
</Pty>
<Instrmt afg="AG" ID="AG" Src="8" CFI="FFI" MMY="2013" Matf="2013"/>
<Qty Typ="AOD" QTYL="134" QTYS="0" />
<Qty Typ="FIN" QTYL="149" QTYS="0" />
<Amt Typ="FMTM" Amt="155065.44" />
</PosRpt>
</Batch>
</XML>