【发布时间】:2014-12-13 09:40:50
【问题描述】:
我有下一个 xml:
<Content>
<article title="I Compute, Therefore I am" id="a1">
<authors>
<author>Philbert von Cookie</author>
<author>Alice Brockman</author>
<author>Pedro Smith</author>
</authors>
<journal>
<name>Journal of Computational Metaphysics</name>
<volume>3</volume>
<issue>7</issue>
<published>04/11/2006</published>
<pages start="42" end="49"/>
</journal>
</article>
...
</Content>
根元素内部有很多类似的文章节点->内容
我已将我的 xml 解析为 python 代码并希望获得最大日期值。这是我的python代码:
try:
import xml.etree.cElementTree as ET
except ImportError:
import xml.etree.ElementTree as ET
tree = ET.ElementTree(file='data.xml')
root = tree.getroot()
root.tag, root.attrib
我正在尝试使用 iterfind() 来获取它,但目前还不行。
for elem in tree.iterfind('(/*/*/journal/published/value[not(text() < preceding-sibling::value/text()) and not(text() < following-sibling::value/text())])[1]'):
print (elem.text)
你能帮我回答我如何为 iterfind() 设置我的 XPATH 或者可能有任何其他方法可以做到这一点? 谢谢。
【问题讨论】:
标签: python xml python-3.x xpath xml-parsing