Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17140 > unrolled thread

Re: Fixing the XML batteries

Started byStefan Behnel <stefan_ml@behnel.de>
First post2011-12-13 15:59 +0100
Last post2011-12-13 15:59 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Fixing the XML batteries Stefan Behnel <stefan_ml@behnel.de> - 2011-12-13 15:59 +0100

#17140 — Re: Fixing the XML batteries

FromStefan Behnel <stefan_ml@behnel.de>
Date2011-12-13 15:59 +0100
SubjectRe: Fixing the XML batteries
Message-ID<mailman.3599.1323788409.27778.python-list@python.org>
Serhiy Storchaka, 13.12.2011 15:27:
> 13.12.11 14:32, Stefan Behnel написав(ла):
>> I stripped my name from the quoted context because I didn't say this.
>
> I am glad to hear this. ;)

It matches my opinion though.


>>> 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.
>
> No, only converting to certain textual representation. Converting entities
> to text (if possible), converting "'" to '"' for quoting, sorting
> attributes, etc.

Yes, that's what C14N is there for, typically used for cryptography, 
hashing, etc. However, MiniDOM doesn't implement that standard, so you're 
on your own here.


>>> 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".
>
> Thanks, I will try this. But I need 2.6+ compatibility.

The ET module is actually quite short (<1700 lines), so you can just copy 
the Py2.7 version into your sources and optionally import it on older 
Python releases. Since you only seem to depend on the serialiser (which is 
worth using anyway because it is much faster in the Py2.7 version), older 
platform versions of cET should also work just fine with that module copy, 
so you can basically just import everything from xml.etree.cElementTree and 
use the ElementTree class and the tostring() function from your own local 
version if the platform version is too old.

Note that ET is also still available as a separately installable package, 
may or may not be simpler to use for you.

Stefan

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web