toprettyxml messes up with whitespaces

kyosohma at gmail.com kyosohma at gmail.com
Tue Oct 2 17:00:54 EDT 2007


On Oct 2, 11:43 am, "Jorgen Bodde" <jorgen.maill... at gmail.com> wrote:
> Hi all,
>
> I parse an XML file, replace a node with a new one (like updating
> cache) and write it back. Every write, new spaces are added. For
> example, first read - update - write cycle;
>
> <var name="APPNAME" status="undefined">
>      My First App
> </var>
>
> Second cycle:
>
> <var name="APPNAME" status="undefined">
>                  My First App
> </var>
>
> Third cycle:
>
> <var name="APPNAME" status="undefined">
>                                            My First App
> </var>
>
> And this goes on. The node is one that is not touched in the XML, it
> is simply written back after reading. I have the same with void spaces
> in between the nodes, I managed to compensate that by stripping the
> lines.
>
> I would like to use toprettyxml to make it user editable and viewable.
> But this is really weird. How can I circumvent this behaviour?
>
> regards,
> - Jorgen

I had similar problems and ended up switching to the lxml package to
solve the issue. I think you can do it with ElementTree too. Maybe
somebody with more experience with the xml / minidom modules will show
up soon.

Mike




More information about the Python-list mailing list