如何解析这个xml?

如何解析这个xml?,xml,python-2.7,xml-parsing,mediawiki,mediawiki-api,Xml,Python 2.7,Xml Parsing,Mediawiki,Mediawiki Api,假设我有来自mediawiki api的以下XML响应。我想找出维基主题修改的最早日期,在本例中是2005-08-23。如何解析xml以找到答案。顺便说一句,我正在使用python <?xml version="1.0"?> <api> <query-continue> <revisions rvcontinue="46214352" /> </query-continue>

假设我有来自mediawiki api的以下XML响应。我想找出维基主题修改的最早日期,在本例中是2005-08-23。如何解析xml以找到答案。顺便说一句,我正在使用python

   <?xml version="1.0"?>
    <api>
      <query-continue>
        <revisions rvcontinue="46214352" />
      </query-continue>
      <query>
        <pageids>
          <id>2516600</id>
        </pageids>
        <pages>
          <page pageid="2516600" ns="0" title="!Kung language">
            <revisions>
              <rev timestamp="2005-08-23T00:58:40Z" />
              <rev timestamp="2005-08-23T01:01:00Z" />
              <rev timestamp="2005-09-02T07:21:37Z" />
              <rev timestamp="2005-09-02T07:24:28Z" />
              <rev timestamp="2006-01-06T07:45:35Z" />
              <rev timestamp="2006-03-22T09:03:23Z" />
              <rev timestamp="2006-03-30T05:50:12Z" />
              <rev timestamp="2006-03-30T20:33:22Z" />
              <rev timestamp="2006-03-30T20:35:05Z" />
              <rev timestamp="2006-03-30T20:37:16Z" />
            </revisions>
          </page>
        </pages>
      </query>
    </api>

但所有这些都是不打印的。

我将使用带有XPath表达式的lxml:

from lxml import etree

root = etree.fromstring(xml)
timestamps = root.xpath('//rev/@timestamp')
至于代码,您没有得到元素的属性。为此,请使用
getAttribute

print y.getAttribute('timestamp')

我将使用lxml和XPath表达式:

from lxml import etree

root = etree.fromstring(xml)
timestamps = root.xpath('//rev/@timestamp')
至于代码,您没有得到元素的属性。为此,请使用
getAttribute

print y.getAttribute('timestamp')

我使用了xml.dom.minidom.parseString函数为什么不使用库来访问API呢?我使用了xml.dom.minidom.parseString函数为什么不使用库来访问API呢?