1👍
✅
Again, your method of getting the id
is wrong, you need to get the attribute pk
from the object
node, not – obj.find("object[@name='pk']").text
– As already answered in – Translate xml string to html, I received error messages .
Then for the current required just get the information – obj.find("field[@name='parent_task_id']").text
, and check if it is equal to 0
and only if it is equal to 0
, append the data to the xmlList.
Example –
self.xmlList = []
for obj in self.xmlData.iter("object"):
parent_task_id = obj.find("field[@name='parent_task_id']").text
if parent_task_id == '0':
self.xmlList.append({'id': obj.get('pk'),
'name': obj.find("field[@name='name']").text,
'parent_task_id': ,
}
Source:stackexchange.com