
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