Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Fixing the XML batteries

Reply
Thread Tools

Re: Fixing the XML batteries

 
 
Stefan Behnel
Guest
Posts: n/a
 
      12-13-2011
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

 
Reply With Quote
 
 
 
 
rurpy@yahoo.com
Guest
Posts: n/a
 
      12-13-2011
On Dec 13, 5:32*am, Stefan Behnel <stefan...@behnel.de> 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?

 
Reply With Quote
 
 
 
 
rurpy@yahoo.com
Guest
Posts: n/a
 
      12-13-2011
On Dec 13, 5:32*am, Stefan Behnel <stefan...@behnel.de> 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.]
 
Reply With Quote
 
Stefan Behnel
Guest
Posts: n/a
 
      12-13-2011
, 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-provolo...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

 
Reply With Quote
 
rurpy@yahoo.com
Guest
Posts: n/a
 
      12-13-2011
On Dec 13, 1:21*pm, Stefan Behnel <stefan...@behnel.de> wrote:
> ru...@yahoo.com, 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-provolo...ree/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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Batteries Charger VS Batteries capacity boulay.patrick@gmail.com Digital Photography 15 11-25-2006 05:42 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Fixing a network rengaw03@hotmail.com Cisco 0 01-20-2006 10:50 PM
fixing port speed at 1000 mbps Noah Davids Cisco 6 10-20-2004 06:31 AM
Sorry. html newsreader needs fixing - Microsoft??? Marko MCSE 1 01-07-2004 04:44 PM



Advertisments