Prev: Tryton 1.6 series is out
Next: pythonMagick question
From: Robert Kern on 27 May 2010 20:13 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
From: Sebastian Bassi on 27 May 2010 22:19 On Thu, May 27, 2010 at 9:13 PM, Robert Kern <robert.kern(a)gmail.com> wrote: > 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. This is not always true. Let me quote an XML tutorial (by Oracle): "What is XML Whitespace? XML considers four characters to be whitespace: the carriage return (\r or ch(13)), the linefeed (\n or ch(10)), the tab(\t), and the spacebar (' '). In XML documents, there are two types of whitespace: Significant whitespace is part of the document content and should be preserved. Insignificant whitespace is used when editing XML documents for readability. These whitespaces are typically not intended for inclusion in the delivery of the document. Usually without DTD or XML schema definition, all whitespaces are significant whitespaces and should be preserved. However, with DTD or XML schema definitions, only the whitespaces in the content are significant as follows: <sig> ------------------ John Smith Product Manager Example.com -------------------- </sig> "
|
Pages: 1 Prev: Tryton 1.6 series is out Next: pythonMagick question |