Skip to content

Commit 7f2c33e

Browse files
committed
Add a function to clean the xml string
This is added because the other parts of the xml are generated without formating.
1 parent a4f4b6e commit 7f2c33e

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

libcomxml/core/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import xml.etree.cElementTree as etree
1818
except ImportError:
1919
import xml.etree.ElementTree as etree
20+
import re
2021

2122

2223
def get_xml_default_encoding():
@@ -25,6 +26,10 @@ def get_xml_default_encoding():
2526
return xml_enc
2627

2728

29+
def clean_xml(xml_string):
30+
return re.sub('\s+<', '<', xml_string)
31+
32+
2833
class Field(object):
2934
"""Base Field class
3035
"""
@@ -249,7 +254,7 @@ def build_tree(self):
249254
continue
250255
self.doc_root.append(item.doc_root)
251256
elif isinstance(item, str):
252-
ele = etree.fromstring(item)
257+
ele = etree.fromstring(clean_xml(item))
253258
self.doc_root.append(ele)
254259
item = None
255260
elif (field.parent or self.root.name) == self.root.name:

0 commit comments

Comments
 (0)