by Süleyman Petek
10. June 2016 12:12
Here i am again with a small blog post, a life saver small Python script to parse your XML files.
I suppose you have an XML file like below that you exported from some other tool ;
<schedule>
<job name="www.mysite.com">
<job name="www.mysite.com">
...
</schedule>
And you want to get all the "name" attribute values from the XML structure, then you can write Java or C Sharp or any other language to parse this file however i think Python is the easiest and the most speed one.
It is as short as below:
import xml.etree.ElementTree
f=open("jobs.txt","w")
e=xml.etree.ElementTree.parse('schedule.xml').getroot()
for atype in e.findall('job'):
f.write(atype.get('name')+"\n")
f.close()
I just create a .txt file here called "jobs.txt" and write all the job names to it.
Enjoy...
63e863b3-1c97-401c-b6c5-09962b995ee7|4|2.3|96d5b379-7e1d-4dac-a6ba-1e50db561b04
Tags: python, xml
Life Saver | Tip