tools: xml_tools.ElementParser do not replace '\n' and '\t' with ' ' by default

This commit is contained in:
souliane 2014-03-15 00:15:49 +01:00
commit b0896b53b7

View file

@ -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()