I'm new to XML processing, and I want to
write a python app that :
1- parse a xml config file,
2- set it's data as default's data in several wxPython
3- could be able to write a pretty xml file with
the data set corrected by the user with the form.
For 1 & 2, the SAX API is very adapted but how to
simply print a new well formed xml file with this data ?
For this point (3), DOM seems to be a smarter choice,
but not for the first points (my parsed config file may
contain a lot of data that I don't need ...)
So what should I do ?
Unfortunately, pullDOM and SAX2DOM docs aren't complete :(
Thanks in advance,
From: email@example.com (Martin v. Loewis) - 2002-06-04 07:10:16
Olivier Grisel <olivier.grisel@...> writes:
> For 1 & 2, the SAX API is very adapted but how to
> simply print a new well formed xml file with this data ?
> For this point (3), DOM seems to be a smarter choice,
> but not for the first points (my parsed config file may
> contain a lot of data that I don't need ...)
If you already have a working SAX solution, I recommend to extend on
it. I understand that you don't want to keep the data in memory that
you don't need, so on write-back, it appears that you need to merge
the XML file on disk with the new in-memory data.
To do so, parse the XML file a second time, and use a XMLGenerator to
generate a new document, inserting the new data at appropriate times.
Alternatively, for the DOM, I recommend that you re-evaluate whether
parsing the entire document into memory is really such a bad thing. It
is quite easy to extract data from the DOM (in my experience, easier
than from a SAX event stream), and the DOM supports modification well.