diff --git a/indentxml.py b/indentxml.py index ee345bb..49aa431 100644 --- a/indentxml.py +++ b/indentxml.py @@ -37,9 +37,10 @@ def run(self, edit): s = self.indentxml(s) view.replace(edit, alltextreg, s) - def indentxml(self, s): + def indentxml(self, s): # convert to utf - s = s.encode("utf-8") + s = s.encode("utf-8") + xmlheader = re.compile("<\?.*\?>").match(s) # convert to plain string without indents and spaces s = re.compile('>\s+([^\s])', re.DOTALL).sub('>\g<1>', s) # replace tags to convince minidom process cdata as text @@ -51,4 +52,6 @@ def indentxml(self, s): s = s.replace('%CDATAESTART%', '') # remove xml header s = s.replace("", "").strip() + if xmlheader: + s = xmlheader.group() + "\n" + s return s \ No newline at end of file