[lxml-dev] Forced attribute value escaping

RommeDeSerieux romme at tesall.ru
Fri Jun 6 13:06:07 CEST 2008


Stefan Behnel wrote:

> How about a code example?

#! /usr/bin/env python
## vim: fileencoding=utf-8
from lxml import etree

node = etree.Element(u'tag_тег')
node.attrib[u'attribute_атрибут'] = u'value_значение'
node.text = u'text_текст'

# what i'm getting (with some linebreaks for email):
# <tag_тег attribute_атрибут="value_&#x437;&#x43D;&#x430;
# &#x447;&#x435;&#x43D;&#x438;&#x435;">text_текст
# </tag_тег>
#
# expected result:
# <tag_тег attribute_атрибут="value_значение">text_текст
# </tag_тег>
print etree.tostring(node, encoding='utf-8')

# P.S. Sorry for sending that to your own address



More information about the lxml-dev mailing list