diff --git a/src/tools/xml_tools.py b/src/tools/xml_tools.py index 13004986..36b6b353 100644 --- a/src/tools/xml_tools.py +++ b/src/tools/xml_tools.py @@ -792,7 +792,11 @@ class ElementParser(object): Found at http://stackoverflow.com/questions/2093400/how-to-create-twisted-words-xish-domish-element-entirely-from-raw-xml/2095942#2095942 (c) Karl Anderson""" - def __call__(self, string): + def __call__(self, string, force_spaces=False): + """ + @param string: the XML string + @param force_spaces: if True, replace occurrences of 'n' and '\t' with ' '. + """ self.result = None def onStart(elem): @@ -809,6 +813,8 @@ class ElementParser(object): parser.ElementEvent = onElement parser.DocumentEndEvent = onEnd tmp = domish.Element((None, "s")) - tmp.addRawXml(string.replace('\n', ' ').replace('\t', ' ')) + if force_spaces: + string = string.replace('\n', ' ').replace('\t', ' ') + tmp.addRawXml(string) parser.parse(tmp.toXml().encode('utf-8')) return self.result.firstChildElement()