14

如何解析来自 Google App Engine 应用程序的 XML?有什么例子吗?

4

3 回答 3

20

自从提出问题以来,Google 已将 pyexpat 列入白名单,其中包括 minidom,因此您可以使用以下代码而无需上传任何库:

from xml.dom import minidom

dom = minidom.parseString('<eg>example text</eg>')

更多信息: http ://docs.python.org/library/xml.dom.minidom.html

于 2009-04-02T19:09:49.197 回答
8

查看有关 XML 和 Python 的现有答案

像这样的东西可以工作:

from cStringIO   import StringIO
from xml.etree   import cElementTree as etree

xml = "<a>aaa<b>bbb</b></a>"

for event, elem in etree.iterparse(StringIO(xml)):
    print elem.text

它打印:

bbb
aaa
于 2009-01-04T13:27:43.383 回答
4

AFAIK Google App Engine 提供了一个相当完整的 Python 环境供您使用。由于 Python 带有“包含电池”,您可能需要评估 vanilla Python 为您提供的不同 API:http: //docs.python.org/library/markup.html

于 2009-01-04T13:14:25.703 回答