Permalink
Browse files

xml header processing, closes #8

  • Loading branch information...
alek-sys committed Nov 24, 2011
1 parent 8d5a5d8 commit 78da832e7af7c9f46a0fa4cf7bd18f5fae90c7d3
Showing with 5 additions and 2 deletions.
  1. +5 −2 indentxml.py
View
@@ -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%', '<![CDATA[').replace('%CDATAEEND%', ']]>')
# remove xml header
s = s.replace("<?xml version=\"1.0\" ?>", "").strip()
+ if xmlheader:
+ s = xmlheader.group() + "\n" + s
return s

0 comments on commit 78da832

Please sign in to comment.