【问题标题】:How do I parse XML from a Google App Engine app?如何解析来自 Google App Engine 应用程序的 XML?
【发布时间】:2009-01-04 13:05:41
【问题描述】:

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

【问题讨论】:

    标签: python xml google-app-engine parsing


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      看看existing answers on XML and 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
      

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 2011-06-01
          • 2011-01-07
          • 1970-01-01
          • 2010-11-13
          • 2010-09-07
          • 2010-12-23
          • 2013-02-05
          • 2011-03-08
          • 1970-01-01
          相关资源
          最近更新 更多