[lxml-dev] problem with etree.tostring and special characters inxml-text-attributes

Hi, I have a problem with the replacement of special characters (xml-entities) in xml-text-properties of the etree.tostring method: After etree.tostring the characters &,<,> are replaced with & < > but ' and " remain in the text-properties. e.g.: <Property Name="Value">final_delim=end, record_delim='\n', delim='|', quote=double</Property> But I need: <Property Name="Value">final_delim=end, record_delim='\n', delim='|', quote=double</Property> I wrote a method that iterates through all text properties after the tostring-method and replaces ' and " of this text-properties in the serialized string, but with large xml-files this consumes a lot of time. Does anybody have a better solution? Kind Regards, Thomas Ing. Thomas Schlögl 4266-UGG3C1 / CFO Datawarehouse Core Solutions Member of the Crossfunctions-Team UniCredit Global Information Services S.p.A. (UGIS S.p.A.) Zweigniederlassung Österreich Nordbergstrasse 13 A-1090 Vienna Room: TZB-6.18 Tel: +43 1 71730 50499 Mobile: - mailto:thomas.schloegl@wave-solutions.com <mailto:anton.wazin@wave-solutions.com>

SCHLÖGL Thomas, 09.11.2009 16:20:
I have a problem with the replacement of special characters (xml-entities) in xml-text-properties of the etree.tostring method:
After etree.tostring the characters &,<,> are replaced with & < > but ' and " remain in the text-properties.
e.g.:
<Property Name="Value">final_delim=end, record_delim='\n', delim='|', quote=double</Property>
But I need:
<Property Name="Value">final_delim=end, record_delim='\n', delim='|', quote=double</Property>
I wrote a method that iterates through all text properties after the tostring-method and replaces ' and " of this text-properties in the serialized string, but with large xml-files this consumes a lot of time.
Does anybody have a better solution?
There is no automatic way to inject these entity references, as it's simply not required to do that. Note that you didn't present any reasoning for your requirement, BTW. What you can do is write an XPath expression that searches the tree for the text you need to replace, and then replace it by entity references before serialising. May or may not be faster than what you do now, but it certainly is safer. Stefan
participants (2)
-
SCHLÖGL Thomas
-
Stefan Behnel