-2
我有兩個xml列表,預期的和實際的。 對於預期列表中的每個預期,我想將它與每個實際進行比較,並確定是否與實際列表中的任何xml匹配。比較Python中xml的兩個列表
每個MESG看起來象下面這樣:
<?xml version="1.0" encoding="utf-8"?>
\n
<stlTxn>
<InstrumnetID>796</InstrumnetID>
<Version>0</Version>
<ProductType>OSTK</ProductType>
<Strike>190.0</Strike>
<AccountID>3236</AccountID>
<Symbol>ALV</Symbol>
<SettlAmount>1520000.0</SettlAmount>
<ClearingBusinessDate>2013-12-18</ClearingBusinessDate>
<CptySettlAccount>8501</CptySettlAccount>
<ProductISIN>DE00004005</ProductISIN>
<ProductCurrency>EUR</ProductCurrency>
<SettlCurrency>EUR</SettlCurrency>
<AccrIntAmount>0.0</AccrIntAmount>
<SettlQuantity>8000.0</SettlQuantity>
<AccountSponsor>CBKFR</AccountSponsor>
<CallPut>0</CallPut>
<DelvSettlPrice>190.0</DelvSettlPrice>
<AccountName>EXY</AccountName>
<CashSettlAmount>0.0</CashSettlAmount>
<Maturity>201312</Maturity>
<Side>0</Side>
<ClearingHouse>ECAG</ClearingHouse>
<AccrIntDays>0</AccrIntDays>
<DeliveryType>DELIVERY_AT_SETTLEMENT_AMOUNT</DeliveryType>
<ProductName>OPT ON ALLIANZ AG HOLDIN</ProductName>
<ProductSymbol>ALV</ProductSymbol>
<Currency>EUR</Currency>
<AccountOwner>CBKFR</AccountOwner>
<ValueDate>2013-12-20</ValueDate>
<ProductID>jigfj</ProductID>
</stlTxn>
我試圖用美麗的湯包:
from bs4 import BeautifulSoup
expected_parsed = BeautifulSoup(expected)
actual_parsed = BeautifulSoup(actual)
if expected_parsed.text != actual_parsed.text:
print "failed"
通過比較你的意思是列表級別或項目級別上的完全匹配? – 2014-10-07 12:59:13
我想比較每個元素的值,例如instrumentid,版本等。 – user2968440 2014-10-07 13:17:30