Re: Fixing the XML batteries

Discussion in 'Python' started by Stefan Behnel, Dec 13, 2011.

  1. Serhiy Storchaka, 13.12.2011 13:17:
    > 09.12.11 17:09, Dirkjan Ochtman wrote:
    >> An at least somewhat informed +1 from me. The ElementTree API is a
    >> very good way to deal with XML from Python, and it deserves to be
    >> promoted over the included alternatives.
    >>
    >> Let's deprecate the NiCad batteries and try to guide users toward the
    >> Li-Ion ones.


    I stripped my name from the quoted context because I didn't say this.


    > I use xml.dom.minidom for XML canonization and convertion:


    Do you mean "canonicalisation"? I.e. C14N? That's not what the code below
    is doing, not at all.


    > doc = xml.dom.minidom.parse( io.BytesIO( data0 ) )
    > encoding = forceEncoding or doc.encoding or str( 'UTF-8' )
    > writer = io.BytesIO()
    > writer = codecs.getwriter( encoding )( writer, 'xmlcharrefreplace' )
    > doc.writexml( writer, encoding = encoding )
    > data = writer.getvalue()
    >
    > How to do this with xml.etree.ElementTree?


    In Python 2.7/3.2, ElementTree has support for C14N serialisation, just
    pass the option method="c14n".

    Stefan
    Stefan Behnel, Dec 13, 2011
    #1
    1. Advertising

  2. Stefan Behnel

    Guest

    On Dec 13, 5:32 am, Stefan Behnel <> wrote:
    ....
    > In Python 2.7/3.2, ElementTree has support for C14N serialisation, just
    > pass the option method="c14n".


    Where does one find information in the Python documentation about
    this?
    , Dec 13, 2011
    #2
    1. Advertising

  3. Stefan Behnel

    Guest

    On Dec 13, 5:32 am, Stefan Behnel <> wrote:
    ....
    > In Python 2.7/3.2, ElementTree has support for C14N serialisation, just
    > pass the option method="c14n".


    Where in the Python docs can one find information about this?

    [previous post disappeared, sorry if I double posted or replied to
    author inadvertently.]
    , Dec 13, 2011
    #3
  4. , 13.12.2011 20:37:
    > On Dec 13, 5:32 am, Stefan Behnel wrote:
    >> In Python 2.7/3.2, ElementTree has support for C14N serialisation, just
    >> pass the option method="c14n".

    >
    > Where does one find information in the Python documentation about
    > this?


    Hmm, interesting. I though it had, but now when I click on the stdlib doc
    link to read the module source (hint, hint), I can see that it only has the
    hooks. The C14N support module of ET 1.3 was not integrated into the
    stdlib. Sorry for not verifying this earlier.

    So you actually need the external package for C14N support. See here:

    http://effbot.org/zone/elementtree-13-intro.htm

    http://hg.effbot.org/et-2009-provolone/src/tip/elementtree/elementtree/ElementC14N.py

    Just to emphasize this once again: it's not more than a single module that
    you can copy into your own code as a fallback import, or deploy in your
    local installations.

    Stefan
    Stefan Behnel, Dec 13, 2011
    #4
  5. Stefan Behnel

    Guest

    On Dec 13, 1:21 pm, Stefan Behnel <> wrote:
    > , 13.12.2011 20:37:
    >
    > > On Dec 13, 5:32 am, Stefan Behnel wrote:
    > >> In Python 2.7/3.2, ElementTree has support for C14N serialisation, just
    > >> pass the option method="c14n".

    >
    > > Where does one find information in the Python documentation about
    > > this?

    >
    > Hmm, interesting. I though it had, but now when I click on the stdlib doc
    > link to read the module source (hint, hint),


    I realize the source is available (having had to use it way too
    many time in the past, not just with ET), but that does not justify
    omission from the docs. However the point is moot since (as you
    say) it seems the Python-distributed ET doesn't contain the c14n
    feature.

    > I can see that it only has the
    > hooks. The C14N support module of ET 1.3 was not integrated into the
    > stdlib. Sorry for not verifying this earlier.
    >
    > So you actually need the external package for C14N support. See here:
    >
    > http://effbot.org/zone/elementtree-13-intro.htm
    >
    > http://hg.effbot.org/et-2009-provolone/src/tip/elementtree/elementtre...
    >
    > Just to emphasize this once again: it's not more than a single module that
    > you can copy into your own code as a fallback import, or deploy in your
    > local installations.


    Right, but many times I try to avoid external dependencies when
    feasible.
    Thanks for the clarifications.
    , Dec 13, 2011
    #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. MS News

    Fixing an Id for a HTML Tag

    MS News, Jul 29, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    322
    Vincent V
    Jul 30, 2003
  2. Daves
    Replies:
    4
    Views:
    470
    Daves
    Mar 10, 2005
  3. Alex

    Batteries Included?

    Alex, Oct 11, 2005, in forum: Python
    Replies:
    7
    Views:
    483
    Paul Rubin
    Oct 11, 2005
  4. John Salerno

    the whole 'batteries included' idea

    John Salerno, Apr 20, 2006, in forum: Python
    Replies:
    3
    Views:
    254
    Ben Sizer
    Apr 21, 2006
  5. batteries included

    , Oct 25, 2006, in forum: Python
    Replies:
    1
    Views:
    248
    Diez B. Roggisch
    Oct 25, 2006
Loading...

Share This Page