I am been trying to implement the logic , But not getting how do I start
My xml as below data in which if you see the child root as 3 attributes
If any one of the attribute is missing it should be populated as null
in that case
Code :
import xml.etree.ElementTree as ET
xml_data='''
<job_details>
<role>
<name>Vilan</name>
<salary>$5.95</salary>
<job_description>Developer</job_description>
</role>
<role>
<name>Dils</name>
<salary>$7.95</salary>
</role>
<role>
<name>Raj</name>
<job_description>Fullstack Developer</job_description>
</role>
</job_details>
'''
get_root_element = ET.fromstring(xml_data)
out = []
for item in get_root_element:
res = ','.join(x.text for x in item)
out.append(res)
Expected output
['Vilan,$5.95,Developer', 'Dils,$7.95,null' , 'Raj',null,'Fullstack Developer' ]