How do I parse XML from a Google App Engine app? Any examples?
如何从Google App Engine应用程序解析XML?任何例子?
3 个解决方案
#1
20
Since the question was asked, Google has whitelisted pyexpat, which includes minidom, so you can use the following code without having to upload any libraries:
自提出问题以来,Google已将白名单pyexpat列入白名单,因此您可以使用以下代码而无需上传任何库:
from xml.dom import minidom
dom = minidom.parseString('<eg>example text</eg>')
More information: http://docs.python.org/library/xml.dom.minidom.html
更多信息:http://docs.python.org/library/xml.dom.minidom.html
#2
8
Take a look at existing answers on XML and Python.
看一下XML和Python的现有答案。
Something like this could work:
像这样的东西可以工作:
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
It prints:
它打印:
bbb
aaa
#3
4
AFAIK Google App Engine provides a fairly complete Python environment for you to use. Since Python comes with "batteries included" you may want to evaluate the different APIs which vanilla Python offers you: http://docs.python.org/library/markup.html
AFAIK Google App Engine提供了一个相当完整的Python环境供您使用。由于Python附带“包含电池”,您可能需要评估vanilla Python为您提供的不同API:http://docs.python.org/library/markup.html
#1
20
Since the question was asked, Google has whitelisted pyexpat, which includes minidom, so you can use the following code without having to upload any libraries:
自提出问题以来,Google已将白名单pyexpat列入白名单,因此您可以使用以下代码而无需上传任何库:
from xml.dom import minidom
dom = minidom.parseString('<eg>example text</eg>')
More information: http://docs.python.org/library/xml.dom.minidom.html
更多信息:http://docs.python.org/library/xml.dom.minidom.html
#2
8
Take a look at existing answers on XML and Python.
看一下XML和Python的现有答案。
Something like this could work:
像这样的东西可以工作:
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
It prints:
它打印:
bbb
aaa
#3
4
AFAIK Google App Engine provides a fairly complete Python environment for you to use. Since Python comes with "batteries included" you may want to evaluate the different APIs which vanilla Python offers you: http://docs.python.org/library/markup.html
AFAIK Google App Engine提供了一个相当完整的Python环境供您使用。由于Python附带“包含电池”,您可能需要评估vanilla Python为您提供的不同API:http://docs.python.org/library/markup.html