Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #34634 > unrolled thread
| Started by | nenad.cikic@gmail.com |
|---|---|
| First post | 2012-12-11 09:47 -0800 |
| Last post | 2012-12-11 18:19 -0800 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.python
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
| From | nenad.cikic@gmail.com |
|---|---|
| Date | 2012-12-11 09:47 -0800 |
| Subject | Create xml with elementtree ET and xml escaping |
| Message-ID | <7caeb6db-41f9-4321-b172-f8ddb6a9ac6d@googlegroups.com> |
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?
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).
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<>&</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<>&</b></a>
Is there some way other than string replace?
Thanks
Nenad
[toc] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2012-12-11 19:59 +0000 |
| Message-ID | <mailman.740.1355256000.29569.python-list@python.org> |
| In reply to | #34634 |
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 (")">
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<>&</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<>&</b></a>
>
> Is there some way other than string replace?
>
[toc] | [prev] | [next] | [standalone]
| From | nenad.cikic@gmail.com |
|---|---|
| Date | 2012-12-11 18:19 -0800 |
| Message-ID | <c5ba2f59-afa8-4715-bc4b-c34c5fbd4579@googlegroups.com> |
| In reply to | #34640 |
Il giorno martedì 11 dicembre 2012 20:59:54 UTC+1, MRAB ha scritto: > > 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 (")"> OK I understood. > > > 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. > Of course I know it is not valid without escaping. But I need it only for signing. I will recheck this if really the web service wants the data to be signed as non escaped. Thanks Nenad
[toc] | [prev] | [next] | [standalone]
| From | Stefan Behnel <stefan_ml@behnel.de> |
|---|---|
| Date | 2012-12-15 10:31 +0100 |
| Message-ID | <mailman.902.1355563883.29569.python-list@python.org> |
| In reply to | #34673 |
nenad.cikic@gmail.com, 12.12.2012 03:19: > Il giorno martedì 11 dicembre 2012 20:59:54 UTC+1, MRAB ha scritto: >> >>> 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. > > Of course I know it is not valid without escaping. But I need it only for signing. I will recheck this if really the web service wants the data to be signed as non escaped. If it expects non-XML, you should tell the owners of the web service so that they can fix it. Stefan
[toc] | [prev] | [next] | [standalone]
| From | nenad.cikic@gmail.com |
|---|---|
| Date | 2012-12-11 18:19 -0800 |
| Message-ID | <mailman.763.1355278772.29569.python-list@python.org> |
| In reply to | #34640 |
Il giorno martedì 11 dicembre 2012 20:59:54 UTC+1, MRAB ha scritto: > > 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 (")"> OK I understood. > > > 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. > Of course I know it is not valid without escaping. But I need it only for signing. I will recheck this if really the web service wants the data to be signed as non escaped. Thanks Nenad
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web