[XML-SIG] Help writing out xml
hgg9140 at seanet.com
Wed Jan 12 03:33:39 CET 2005
An option is to write the xml manually. That is, each object in your
"model" (as in model-view-controller) has a "to_xml" method which takes
a fileobject (sys.stdout is default), and writes itself in XML to
Indents are controlled by some formatting mechanism. I
personally use my "tabbedwriter":
I've done this with a lot of XML's and find it is easy to control and
trivial to setup. Where there is inheritance in the "model", a lot of
the XML output can be done by the base object(s).
On Tue, 11 Jan 2005 17:07:14 -0500
Willis <willismonroe at verizon.net> wrote:
> I'm writing a script that edits and writes xml to a
> gaim(http://gaim.sourceforge.net) configuration file. However the
> problem I'm having is I've found no way of outputting xml in python
> that preserves text nodes.
> i.e. gaim writes
> in it's xml file somehow, and the best I can get python to do is:
> which gaim won't parse.
> but I was curious how can the toprettyxml() function change the xml so
> drastically that it parses itself differently as illustrated in these
> to lines, where the only difference is the writing function
> (toprettyxml, and toxml.
> ccount").childNodes.data = u'\n willis\n'
> ildNodes.data = u'willis'
> I know that printing with toxml() works, however toxml() also writes
> everything on one line, something that is very impractical for
> supposedly readable files.
> basically I'm looking for a way to print xml, where the output is nice
> looking, but the text nodes are preserved perfectly, as in no extra
> line breaks and tabs that toprettyxml() inserts on it's own.
> XML-SIG maillist - XML-SIG at python.org
hgg9140 at seanet.com www.seanet.com/~hgg9140
More information about the XML-SIG