i’m just trying to work out a simple way opening, editing and saving an xml file using python.
so far i have managed to open a file and write it to output.
i have not, however managed to print it out easily so that i know what’s in any given object, traverse the object model, edit tags and attributes, or write the xml to a file.
from lxml import etree
root = etree.parse('test.xml')
print etree.tostring(root);
i’m used to using simpleXML for php, which is a breeze.
please help, as i am finding the documentation difficult to comprehend 🙁
thanks 🙂
The lxml tutorial is nice and easy to understand. Check it out here and give it a try. It takes some time to used to, but as with everything, the initial steps are difficult.
Another excellent tutorial (and reference) I recommend is the tutorial by John Shipman. You should seriously give it a read.
I recommend: Read the tutorial and the book by Shipman. Then try out parsing simple XML files.
lxml is worth learning. Once you do learn it, you will love it. PS: All that I said is based on my personal experience.
EDIT: Based on your comment, you should use this instead of lxml then. Here is an easy to understand tutorial.