是的。示例XML文件:
<?xml version="1.1" encoding="iso-8859-1"?>
<container>
<person name="Jim">
<number type="home" value="000-000-0000"/>
<number type="work" value="111-111-1111"/>
</person>
<person name="Fred">
<number type="home" value="222-222-2222"/>
<number type="work" value="333-333-3333"/>
</person>
</container>
示例腳本:
from xml.etree.ElementTree import ElementTree
f = open('/path/to/xml/file', 'r')
xml = ElementTree(file=f)
for person in xml.findall('person'):
print(person.attrib['name'])
for number in person.findall('number'):
print('%s -> %s' % (number.attrib['type'], number.attrib['value']))
打印:
Jim
home -> 000-000-0000
work -> 111-111-1111
Fred
home -> 222-222-2222
work -> 333-333-3333
這是Python 2.5的一部分,所以應該在App Engine中工作。您可以調整腳本以從URL獲取XML。
+1代碼創建示例XML :-) – Axarydax 2010-12-29 18:37:12