У меня есть файл аннотации xml, в котором есть теги , я хочу найти тег для каждого действия и прочитать его значение (проверьте, является ли он Blur или нет) и для каждого действия я также хотите вернуть и . Как я могу это сделать? Есть ли инструментарий? Нужно ли читать каждый <тег> и находить всех его дочерних элементов?
<action>
<temporal_region>
<start_time>2683480</start_time>
<stop_time>2684448</stop_time>
</temporal_region>
<action_type/>
<state>1</state>
<actuator>Incident</actuator>
<description/><verb/><affected_list/><instrument_list/><recipient/>
<origin>Blur</origin>
<destination/>
</action>
Редактировать:
Предложения, слегка расширенные для нескольких действий:
from bs4 import BeautifulSoup as bs
xml = """
<action>
<temporal_region>
<start_time>2683480</start_time>
<stop_time>2684448</stop_time>
</temporal_region>
<action_type/>
<state>1</state>
<actuator>Incident</actuator>
<description/><verb/><affected_list/><instrument_list/><recipient/>
<origin>Blur</origin>
<destination/>
</action>
<action>
<temporal_region>
<start_time>2683480</start_time>
<stop_time>2684448</stop_time>
</temporal_region>
<action_type/>
<state>1</state>
<actuator>Incident</actuator>
<description/><verb/><affected_list/><instrument_list/><recipient/>
<origin>Blur</origin>
<destination/>
</action>"""
soup = bs(xml, 'html.parser')
origin = soup.find('origin').text
print(len(origin))
start_time = soup.find('start_time').text
stop_time = soup.find('stop_time').text
if origin == 'Blur':
print("success")
Возвращает 4, что, я полагаю, является открывающим и закрывающим тегами источника, в то время как у меня есть только 2 элемента.