gpt4 book ai didi

python - 使用 cElementTree 从 XML 查找所有节点

转载 作者:行者123 更新时间:2023-12-01 00:01:11 26 4
gpt4 key购买 nike

有没有办法使用 cElementTree 查找 xml 树中的所有节点? findall 方法仅适用于指定的标签。

最佳答案

您可以使用XPath paths关于 findall 方法:

The 1.2 release supports simple element location paths. In its simplest form, a location path is one or more tag names, separated by slashes (/).

You can also use an asterisk (*) instead of a tag name, to match all elements at that level. For example, */subtag returns all subtag grandchildren.

An empty tag (//) is used to search on all levels of the tree, beneath the current level. The empty tag must always be followed by a tag name or an asterisk.

etree.findall('.//*')

关于python - 使用 cElementTree 从 XML 查找所有节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/304216/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com