我正在尝试使用欧元汇率解析来自欧洲中央银行的 XML 文件。不幸的是,我无法解析 XML 文件。当我删除困难的部分(与“gesmes”相关的所有内容)时,迭代“Cube”元素没有问题,但我无法处理 xml 文件的“gesmes”部分。我为此使用了 ElementTree API。
示例 XML 文件: http: //www.ecb.int/stats/eurofxref/eurofxref-daily.xml
<?xml version="1.0" encoding="UTF-8"?>
<gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref">
<gesmes:subject>Reference rates</gesmes:subject>
<gesmes:Sender>
<gesmes:name>European Central Bank</gesmes:name>
</gesmes:Sender>
<Cube>
<Cube time='2013-06-21'>
<Cube currency='USD' rate='1.3180'/>
<Cube currency='JPY' rate='128.66'/>
<Cube currency='BGN' rate='1.9558'/>
<Cube currency='CZK' rate='25.825'/>
<Cube currency='DKK' rate='7.4582'/>
<Cube currency='GBP' rate='0.85330'/>
<Cube currency='HUF' rate='298.87'/>
<Cube currency='LTL' rate='3.4528'/>
<Cube currency='LVL' rate='0.7016'/>
<Cube currency='PLN' rate='4.3289'/>
<Cube currency='RON' rate='4.5350'/>
<Cube currency='SEK' rate='8.6927'/>
<Cube currency='CHF' rate='1.2257'/>
<Cube currency='NOK' rate='7.9090'/>
<Cube currency='HRK' rate='7.4905'/>
<Cube currency='RUB' rate='43.2260'/>
<Cube currency='TRY' rate='2.5515'/>
<Cube currency='AUD' rate='1.4296'/>
<Cube currency='BRL' rate='2.9737'/>
<Cube currency='CAD' rate='1.3705'/>
<Cube currency='CNY' rate='8.0832'/>
<Cube currency='HKD' rate='10.2239'/>
<Cube currency='IDR' rate='13088.24'/>
<Cube currency='ILS' rate='4.7891'/>
<Cube currency='INR' rate='78.1200'/>
<Cube currency='KRW' rate='1521.52'/>
<Cube currency='MXN' rate='17.5558'/>
<Cube currency='MYR' rate='4.2222'/>
<Cube currency='NZD' rate='1.7004'/>
<Cube currency='PHP' rate='57.707'/>
<Cube currency='SGD' rate='1.6790'/>
<Cube currency='THB' rate='41.003'/>
<Cube currency='ZAR' rate='13.4906'/>
</Cube>
</Cube>
</gesmes:Envelope>
我想要的是搜索特定货币(来自用户输入)并取回汇率,以便我可以使用结果。