Re: ElementTree write creates large one line XML file ....

Discussion in 'Python' started by Robert Kern, May 28, 2010.

  1. Robert Kern

    Robert Kern Guest

    On 5/27/10 7:52 PM, robert somerville wrote:
    > Hi I am using Ubuntu 9.10 and Python 2.6.4 ..
    >
    > when I create an ElementTree object and the write it out using:
    >
    > xml.etree.ElementTree.write() , I get one single long single line
    > files, instead of something that looks reasonable , what gives ??? (and
    > is it important ??)


    ElementTree writes exactly what you tell it to. In XML, whitespace is
    significant. If you want newlines and/or indentation to make it pretty-looking,
    then you need to add those to your elements.

    Fredrik provides an example function for doing this:

    http://effbot.org/zone/element-lib.htm#prettyprint

    --
    Robert Kern

    "I have come to believe that the whole world is an enigma, a harmless enigma
    that is made terrible by our own mad attempt to interpret it as though it had
    an underlying truth."
    -- Umberto Eco
     
    Robert Kern, May 28, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. scad
    Replies:
    23
    Views:
    1,177
    Alf P. Steinbach
    May 17, 2009
  2. Kee Nethery
    Replies:
    12
    Views:
    2,094
    Stefan Behnel
    Jun 27, 2009
  3. Stefan Behnel
    Replies:
    0
    Views:
    779
    Stefan Behnel
    May 4, 2010
  4. hackingKK
    Replies:
    4
    Views:
    1,433
    Diez B. Roggisch
    Oct 31, 2010
  5. Replies:
    1
    Views:
    400
Loading...

Share This Page