Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.alphanet.ch!alphanet.ch!news.imp.ch!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!news-transit.tcx.org.uk!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'package,': 0.03; 'context': 0.04; 'python': 0.08; 'attributes,': 0.09; 'optionally': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'anyway': 0.09; 'converting': 0.15; 'cet': 0.16; 'doing,': 0.16; 'from:addr:behnel.de': 0.16; 'from:addr:stefan_ml': 0.16; 'from:name:stefan behnel': 0.16; 'lines),': 0.16; 'received:mnet- online.de': 0.16; 'stripped': 0.16; 'subject:XML': 0.16; 'thanks,': 0.18; '>>>': 0.18; 'simpler': 0.18; '(which': 0.19; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'versions': 0.23; 'though.': 0.23; 'fine': 0.24; 'stefan': 0.24; 'code': 0.25; 'module': 0.26; 'function': 0.27; 'import': 0.27; 'pass': 0.29; 'matches': 0.29; 'class': 0.29; 'seem': 0.30; 'for,': 0.30; 'separately': 0.30; 'xml': 0.31; "didn't": 0.31; 'version': 0.32; 'quite': 0.32; 'typically': 0.32; 'implement': 0.32; 'header:User- Agent:1': 0.33; 'actually': 0.33; 'this.': 0.33; 'header:X -Complaints-To:1': 0.33; 'there': 0.33; 'to:addr:python-list': 0.34; 'too': 0.34; 'certain': 0.34; 'all.': 0.34; 'however,': 0.36; '8bit%:86': 0.37; 'depend': 0.37; 'skip:" 10': 0.37; 'but': 0.37; 'using': 0.38; 'received:org': 0.38; 'i.e.': 0.39; 'option': 0.39; 'received:de': 0.39; 'should': 0.39; 'to:addr:python.org': 0.40; 'worth': 0.61; 'your': 0.61; 'below': 0.63; 'you.': 0.63; 'here.': 0.66; 'glad': 0.68; 'skip:\xd0 20': 0.77; 'received:88.217': 0.84; 'standard,': 0.84; 'releases.': 0.91; 'old.': 0.97 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Stefan Behnel Subject: Re: Fixing the XML batteries Date: Tue, 13 Dec 2011 15:59:52 +0100 References: <4EE7425A.2090006@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: ppp-88-217-94-187.dynamic.mnet-online.de User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110921 Lightning/1.0b2 Thunderbird/3.1.15 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 42 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1323788409 news.xs4all.nl 6903 [2001:888:2000:d::a6]:37789 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17140 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