no line breaks in xml file with elementTree

Discussion in 'Python' started by hackingKK, Oct 31, 2010.

  1. hackingKK

    hackingKK Guest

    Hello all.
    I want to know if there is a way to have the ElementTree module write to
    an xml file with line breaks?
    I find that when I use the write function from the module on a tree
    object, the resulting file has no line breaks. I don't want to use
    prittyprint because it is adding extra tabs to the file and they are
    either counted as extra nodes or in case of element.text with
    elementtree, they are rendered as a part of the text, both being
    impractical results.
    So is there a middle approach where we can have some thing similar to
    prityprint but without the extra tabs and yet having a properly line
    breaked xml file?
    Further more, I just was curious why elementtree is not having the
    namespace facility?
    xml.dom.minidom has a way to generate tags with namespaces.
    Any thing similar in elementTree?

    happy hacking.
    Krishnakant.
     
    hackingKK, Oct 31, 2010
    #1
    1. Advertising

  2. In message <>, hackingKK
    wrote:

    > I want to know if there is a way to have the ElementTree module write to
    > an xml file with line breaks?


    Why does it matter? The XML files you generate are not for humans to look
    at, are they?

    > Further more, I just was curious why elementtree is not having the
    > namespace facility?


    ElementTree handles namespaces just fine.
     
    Lawrence D'Oliveiro, Oct 31, 2010
    #2
    1. Advertising

  3. hackingKK

    hackingKK Guest

    On Sunday 31 October 2010 01:58 PM, Lawrence D'Oliveiro wrote:
    > In message<>, hackingKK
    > wrote:
    >
    >
    >> I want to know if there is a way to have the ElementTree module write to
    >> an xml file with line breaks?
    >>

    > Why does it matter? The XML files you generate are not for humans to look
    > at, are they?
    >


    So is there a function to generate tags with namespace?

    happy hacking.
    Krishnakant.
     
    hackingKK, Oct 31, 2010
    #3
  4. hackingKK, 31.10.2010 10:04:
    > On Sunday 31 October 2010 01:58 PM, Lawrence D'Oliveiro wrote:
    >> hackingKK wrote:
    >>> Further more, I just was curious why elementtree is not having the
    >>> namespace facility?

    >>
    >> ElementTree handles namespaces just fine.

    >
    > So is there a function to generate tags with namespace?


    Yes, it's called "Element", as in

    el = ET.Element('{http://the.name/space}tag')

    Reading the docs helps a lot here.

    Stefan
     
    Stefan Behnel, Oct 31, 2010
    #4
  5. hackingKK <> writes:

    > On Sunday 31 October 2010 01:58 PM, Lawrence D'Oliveiro wrote:
    >> In message<>, hackingKK
    >> wrote:
    >>
    >>
    >>> I want to know if there is a way to have the ElementTree module write to
    >>> an xml file with line breaks?
    >>>

    >> Why does it matter? The XML files you generate are not for humans to look
    >> at, are they?
    >>

    >
    > So is there a function to generate tags with namespace?


    http://lmgtfy.com/?q=element tree namespac

    --

    Diez
     
    Diez B. Roggisch, Oct 31, 2010
    #5
    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. Raj Mudaliar
    Replies:
    0
    Views:
    2,316
    Raj Mudaliar
    Jul 14, 2003
  2. Kee Nethery
    Replies:
    12
    Views:
    2,205
    Stefan Behnel
    Jun 27, 2009
  3. Robert Kern
    Replies:
    0
    Views:
    641
    Robert Kern
    May 28, 2010
  4. Stefan Behnel
    Replies:
    1
    Views:
    1,036
    David Vicente
    Feb 9, 2011
  5. Marek Stepanek
    Replies:
    12
    Views:
    441
    Peter J. Holzer
    Sep 2, 2006
Loading...

Share This Page