mio file XML si presenta come la seguente:Utilizzando XPath in ElementTree
<?xml version="1.0"?>
<ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2008-08-19">
<Items>
<Item>
<ItemAttributes>
<ListPrice>
<Amount>2260</Amount>
</ListPrice>
</ItemAttributes>
<Offers>
<Offer>
<OfferListing>
<Price>
<Amount>1853</Amount>
</Price>
</OfferListing>
</Offer>
</Offers>
</Item>
</Items>
</ItemSearchResponse>
Tutto quello che voglio fare è estrarre il ListPrice.
Questo è il codice che sto usando:
>> from elementtree import ElementTree as ET
>> fp = open("output.xml","r")
>> element = ET.parse(fp).getroot()
>> e = element.findall('ItemSearchResponse/Items/Item/ItemAttributes/ListPrice/Amount')
>> for i in e:
>> print i.text
>>
>> e
>>
Assolutamente nessuna uscita. Ho anche provato
>> e = element.findall('Items/Item/ItemAttributes/ListPrice/Amount')
Nessuna differenza.
Cosa sto sbagliando?
Grazie mille. Stava per sbattere la testa contro un muro ripetutamente. –
Nessun problema, dovrebbero dare un esempio con namespace nella loro documentazione per find e findall. –
beh, avrebbero potuto rendere questo più chiaro nella documentazione ... grazie! – jorrebor