14 python xml google-app-engine parsing
如何从Google App Engine应用程序解析XML?任何例子?
Ric*_*son 20
自从问到这个问题以来,谷歌已经将pyexpat列入白名单,其中包括minidom,因此您可以使用以下代码而无需上传任何库:
from xml.dom import minidom
dom = minidom.parseString('<eg>example text</eg>')
Run Code Online (Sandbox Code Playgroud)
更多信息:http: //docs.python.org/library/xml.dom.minidom.html
像这样的东西可以工作:
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
Run Code Online (Sandbox Code Playgroud)
它打印:
bbb
aaa
Run Code Online (Sandbox Code Playgroud)
AFAIK Google App Engine 提供了一个相当完整的 Python 环境供您使用。由于 Python 附带“包含电池”,您可能需要评估普通 Python 为您提供的不同 API: http: //docs.python.org/library/markup.html