ElementTree, XML and Unicode -- C0 Controls

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sébastien Boisgérault

    #1

    ElementTree, XML and Unicode -- C0 Controls

    Hi all,

    The unicode code points in the 0000-001F range --
    except newline, tab, carriage return -- are not legal
    XML 1.0 characters.

    Attempts to serialize and deserialize such strings
    with ElementTree will fail:
    >>elt = Element("root", char=u"\u0000")
    >>xml = tostring(elt)
    >>xml
    '<root char="\x00" />'
    >>fromstring(xm l)
    [...]
    xml.parsers.exp at.ExpatError: not well-formed (invalid token): line 1,
    column 12

    Good ! But I was expecting a failure *earlier*, in
    the "tostring" function -- I basically assumed that
    ElementTree would refuse to generate a XML
    fragment that is not well-formed.

    Could anyone comment on the rationale behind
    the current behavior ? Is it a performance issue,
    the search for non-valid unicode code points being
    too expensive ?

    Cheers,

    SB

  • Fredrik Lundh

    #2
    Re: ElementTree, XML and Unicode -- C0 Controls

    Sébastien Boisgérault wrote:
    Could anyone comment on the rationale behind
    the current behavior ? Is it a performance issue,
    the search for non-valid unicode code points being
    too expensive ?
    the default serializer doesn't do any validation or well-formedness checks at all; it assumes
    that you know what you're doing.

    </F>



    Comment

    • Sébastien Boisgérault

      #3
      Re: ElementTree, XML and Unicode -- C0 Controls



      On Dec 11, 4:51 pm, "Fredrik Lundh" <fred...@python ware.comwrote:
      Sébastien Boisgérault wrote:
      Could anyone comment on the rationale behind
      the current behavior ? Is it a performance issue,
      the search for non-valid unicode code points being
      too expensive ?
      the default serializer doesn't do any validation or well-formedness checks at all; it assumes
      that you know what you're doing.

      </F>
      Fair enough !

      Thanks Fredrik.

      SB

      Comment

      Working...