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


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

Re: how to get Python to insert special characters in an xml file?

Started byPhilip Semanchuk <philip@semanchuk.com>
First post2011-07-15 08:56 -0400
Last post2011-07-15 08:56 -0400
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: how to get Python to insert special characters in an xml file? Philip Semanchuk <philip@semanchuk.com> - 2011-07-15 08:56 -0400

#9548 — Re: how to get Python to insert special characters in an xml file?

FromPhilip Semanchuk <philip@semanchuk.com>
Date2011-07-15 08:56 -0400
SubjectRe: how to get Python to insert special characters in an xml file?
Message-ID<mailman.1065.1310738714.1164.python-list@python.org>
On Jul 15, 2011, at 7:53 AM, hackingKK wrote:

> Hello all.
> I am currently developing a python application which reads and writes some data to an xml file.
> I use the elementTree library for doing this.
> My simple question is that if I have some thing like & as in "kk & company " as organisation name, how can I have Python take this as a litteral string including the & sign and put in the <orgname> </orgname> tag?
> Even same applies while reading the file.  I would like to have the & come as a part of the literal string.

Hi Krishnakant,
You don't need to do anything special to insert metacharacters like & and < and > into XML using ElementTree. Just treat them as normal text and ElementTree will change them to entity references (&amp;, etc.) when it writes your file to disk. 

If you're having a specific problem with this, post some code.

Cheers
Philip

[toc] | [standalone]


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


csiph-web