Hi there
I have following XML document that i want to read in python code. i know how to read, thing is i want to make hash/list from this XML document.

<?xml version="1.0" ?>
‐<TradeExt>
‐ <fxall category="buyer" version="2.0">
‐<tradeHeader>
<sourceId>test_sourceId1</sourceId>
<pmsId>4521363.0.0</pmsId>
<fundId>ACCT1@TESTCUST</fundId>
</tradeHeader>
‐ <tradeStatus>
<dealImmediately>F</dealImmediately>
<blockImmediately>F</blockImmediately>
</tradeStatus>
‐ <tradeFinancials>
<userDefinedFields Name="UDF_6">six</userDefinedFields>
<userDefinedFields Name="UDF_7">seven</userDefinedFields>
<remarks>test remark</remarks>
</tradeFinancials>
</fxall>

‐ <fxall category="buyer" version="2.0">
‐ <tradeHeader>
<sourceId>test-sourceId2</sourceId>
<pmsId>4521363.0.1</pmsId>
<fundId>ACCT2@TESTCUST</fundId>
<pomsId>4521363_0_1_0</pomsId>
<blockTicketId>4521363</blockTicketId>
<lastNegotiator>trader@TESTCUST</lastNegotiator>
<traderId>null Maker Name</traderId>
</tradeHeader>
‐ <tradeStatus>
<state>Completed</state>
<nonNegotiated>F</nonNegotiated>
<blockImmediately>F</blockImmediately>
</tradeStatus>
‐ <tradeFinancials>
<spotRate>1.4144</spotRate>
<forwardPoints>0</forwardPoints>
<allinRate>1.4144</allinRate>
<indicativeRate>1.1695</indicativeRate>
<counterParty>ABN</counterParty>
<userDefinedFields Name="UDF_9">nine</userDefinedFields>
<userDefinedFields Name="UDF_10">ten</userDefinedFields>
<userDefinedFields Name="UDF_11">eleven</userDefinedFields>
<remarks>test remark2</remarks>
</tradeFinancials>
</fxall>
</TradeExt>

-----------------------------END OF XML FILE-----------------------------
How i can make a list/hash for furthur using in code? that i can access keys and values in furthur code.
I want to have result like this

Field [sourceId : test_sourceId1 , pmsId : 4521363.0.0,fundId:ACCT1@TESTCUST, and so on..............]

I dont want to use getElementsByTagName.And i am using xml.dom import minidom already.

Recommended Answers

All 2 Replies

You must write XML Parser using xml.sax.handler. Read this document

if you want it done quickly, use xml.dom.minidom

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.