[英]ElementTree cannot find element
我有一个XML文档,为此在下面的复制器中包括一个足够的子集,为此tree.find()
返回任何结果:
import xml.etree.ElementTree as ET
xml_str = '''
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System/>
</Event>
'''
tree = ET.fromstring(xml_str)
system = tree.find('System')
我希望system
现在保留<System>
标记,但它为None
。 我在这里想念什么吗?
当我使用数组索引(例如tree[0][0]
)时,它确实起作用了。
在搜索中使用名称空间:
>>> doc.find('{http://schemas.microsoft.com/win/2004/08/events/event}System')
<Element {http://schemas.microsoft.com/win/2004/08/events/event}System at 0x10167e5a8>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.