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


Groups > comp.lang.python > #34640

Re: Create xml with elementtree ET and xml escaping

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!rt.uk.eu.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
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; 'python.': 0.02; 'example:': 0.03; 'encoded': 0.05; 'skip:\\ 20': 0.05; 'escape': 0.07; 'skip:\\ 10': 0.07; 'delimiter': 0.09; 'subject:xml': 0.09; 'xml.': 0.09; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'outputs': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'value:': 0.16; 'string': 0.17; 'wrote:': 0.17; 'skip:" 30': 0.20; 'noted': 0.22; 'posted': 0.22; 'seems': 0.23; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'skip:" 20': 0.26; 'skip:e 30': 0.27; 'escaped': 0.29; 'received:192.168.1.3': 0.29; 'case,': 0.29; 'received:84': 0.32; 'to:addr:python-list': 0.33; 'skip:b 20': 0.34; 'there': 0.35; 'ability': 0.36; 'but': 0.36; 'subject:with': 0.36; 'too': 0.36; 'xml': 0.37; 'does': 0.37; 'being': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'hello,': 0.39; 'received:192.168': 0.40; 'first': 0.61; 'dead': 0.62; 'email addr:gmail.com': 0.63; 'header :Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'special': 0.73; '8bit%:24': 0.84; 'escaping': 0.84; 'reply- to:addr:python.org': 0.84; 'singing': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.0 cv=ZenDwLpA c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=O2Kvzccb_dQA:10 a=TAW_PoC2yOoA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=AzHErvk5NgcA:10 a=pGLkceISAAAA:8 a=39Yv7vxK_F3Sz6NyE4gA:9 a=QEXdDO2ut3YA:10 a=MSl-tDqOz04A:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117
X-AUTH mrabarnett:2500
Date Tue, 11 Dec 2012 19:59:54 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/17.0 Thunderbird/17.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Create xml with elementtree ET and xml escaping
References <7caeb6db-41f9-4321-b172-f8ddb6a9ac6d@googlegroups.com>
In-Reply-To <7caeb6db-41f9-4321-b172-f8ddb6a9ac6d@googlegroups.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.740.1355256000.29569.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1355256000 news.xs4all.nl 6950 [2001:888:2000:d::a6]:49263
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:34640

Show key headers only | View raw


On 2012-12-11 17:47, nenad.cikic@gmail.com wrote:
> Hello, I have posted the same in XML group but it seems pretty dead there so I will repost here.
>
> I am new to xml processing in python.
> I am looking to create XML. Xml is not too difficult so I thought to create it manually using ElementTree.
> First I noted that ET.toString does escape <>& but not " and '
> Is that normal?
>
" needs to be encoded when it's in an attribute's value:

     <tag value="a quote (&quot;)">

because it's also being used as a delimiter in that case, but elsewhere
it has no special meaning.

> Since I have also the need to sign the XML I need the ability to create xml but without xml escaping (unescaped data are signed).

XML with the escaping isn't valid XML.

> If i do ET.toString(root,'utf8',text') i do not get the xml tags and if I do ET.toString(root,'utf8') I get escaped chars.
> For example:
> a=ET.Element('a')
> b=ET.SubElement(a,'b')
> b.text=u"šđ<>&"
>
> ET.tostring(a,'utf8')
> outputs to
> "<?xml version='1.0' encoding='utf8'?>\n<a><b>\xc5\xa1\xc4\x91&lt;&gt;&amp;</b></a>"
>
> ET.tostring(a,'utf8',method='text')
> outputs to
> "\xc5\xa1\xc4\x91<>&"
>
> and I need before singing
> <a><b>\xc5\xa1\xc4\x91<>&</b></a>
> and after signing
> <a><b>\xc5\xa1\xc4\x91&lt;&gt;&amp;</b></a>
>
> Is there some way other than string replace?
>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Create xml with elementtree ET and xml escaping nenad.cikic@gmail.com - 2012-12-11 09:47 -0800
  Re: Create xml with elementtree ET and xml escaping MRAB <python@mrabarnett.plus.com> - 2012-12-11 19:59 +0000
    Re: Create xml with elementtree ET and xml escaping nenad.cikic@gmail.com - 2012-12-11 18:19 -0800
      Re: Create xml with elementtree ET and xml escaping Stefan Behnel <stefan_ml@behnel.de> - 2012-12-15 10:31 +0100
    Re: Create xml with elementtree ET and xml escaping nenad.cikic@gmail.com - 2012-12-11 18:19 -0800

csiph-web