[英]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.