xml.dom.minidom - bug ? future ?

Discussion in 'Python' started by Roman Yakovenko, Sep 4, 2003.

  1. Hi. What I don't understand is why I dump to xml string that contains
    new - lines and when I read it from xml new lines replaced by spaces.
    May be I do something wrong? Or may be I just need to define encoding?
    Here is some simple program that reproduce it.


    #------------------
    import xml.dom.minidom

    doc = """1
    2
    3
    4
    5
    6
    7
    8"""

    def save():
    DOMImpl = xml.dom.minidom.getDOMImplementation()
    controller_doc = DOMImpl.createDocument( None, "Multiline", None)
    controller_elem = controller_doc.documentElement
    controller_elem.setAttribute( "str", doc )
    controller_xml = controller_elem.toxml()
    session = file( "c:/temp/__stam222.xml", 'w+' )
    session.write( controller_xml )
    session.close()

    def load():
    controller_doc = xml.dom.minidom.parse( "c:/temp/__stam222.xml" )
    controller_elem = controller_doc.documentElement
    ldoc = controller_elem.getAttribute( "str" )
    print ldoc
    return ldoc

    save()

    assert doc == load()

    #------------------

    Thanks

    Roman
    Roman Yakovenko, Sep 4, 2003
    #1
    1. Advertising

  2. Roman Yakovenko wrote:

    > Hi. What I don't understand is why I dump to xml string that contains
    > new - lines and when I read it from xml new lines replaced by spaces.
    > May be I do something wrong?


    You should not use new line characters in attribute values. According to
    the XML specification, the XML processor must replace them with white
    space, see

    http://www.w3.org/TR/REC-xml#AVNormalize

    Regards,
    Martin
    =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?=, Sep 4, 2003
    #2
    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. Greg Wogan-Browne
    Replies:
    1
    Views:
    802
    Uche Ogbuji
    Jan 28, 2005
  2. Maksim Kasimov

    is it bug or feature in xml.dom.minidom?

    Maksim Kasimov, Mar 2, 2007, in forum: Python
    Replies:
    1
    Views:
    296
    Paul Boddie
    Mar 2, 2007
  3. Replies:
    3
    Views:
    530
    Stefan Behnel
    Aug 3, 2007
  4. JYA
    Replies:
    2
    Views:
    293
    Marc Christiansen
    Apr 30, 2008
  5. Sampsa Riikonen

    xml.dom.minidom bug ?

    Sampsa Riikonen, Dec 8, 2008, in forum: Python
    Replies:
    1
    Views:
    552
    Diez B. Roggisch
    Dec 8, 2008
Loading...

Share This Page