Hi B3D00 - To answer your question, it really comes down to preference. You could use SAX or DOM (or mini dom). I prefer DOM and miniDOM (which is even easier), because it allows you to treat the file as a tree - which is handy, and easier to de-bug in your head.
To Load a file, something like this should work.
from xml.dom import utils,core
# Read an XML document into a DOM object
reader = utils.FileReader('Somefile.xml')
# Retrieve top level DOM document object
doc = reader.document
# Loop through the nodes ()
for n in doc.documentElement.childNodes:
if n.localName == "somenodename":
# lets say you have a node with a collection of nodes
# nested inside, you could test for a certain localName
# (node name) and then do for i in n.childNodes - and then loop through
# the children (thats where the tree structure comes in handy!).
to write an xml file then you could just do something like this:
from xml.dom.minidom import getDOMImplementation
dom = getDOMImplementation()
doc = dom.createDocument(None, "root", None)
# the top root node called "root" by the line above
# could be any name you choose though.
topElement = doc.documentElement
firstElement = doc.createElement("anyname")
#append the element created above as a child of the root node
#append a text node as a child of the 'anyname' node
textNode = doc.createTextNode("Some text here")
xmlString = doc.toprettyxml(" " * 4)
#then print out the xmlstring variable to a file
which would produce something like this:
some text here
I hope this helps - It may look sorta daunting, but seriously it’s alot more versatile and easier in the long run than coming up with your own ‘filetype’ and crudely parsing it as best you can with commas to seperate values etc.
I haven’t tested the code, so don’t shoot me if it doesn’t work! but you should get the gist of it. If you need more help with it just PM with some details of what your trying to do and I’ll write up some example code for you.