daily pastebin goal
13%
SHARE
TWEET

Untitled

a guest May 5th, 2011 412 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. contents = doc.toxml()
  3.  
  4. def prettyxml(input):
  5.         input = input.replace("><",">\n<")
  6.         output = ''
  7.  
  8.         indentlevel = -1
  9.         for line in input.split('\n'):
  10.                 if line == '<?xml version="1.0" ?>':
  11.                         output += line + "\n"
  12.                         continue
  13.                
  14.                 if line[:2] != "</":
  15.                         indentlevel += 1
  16.                         output += "  "*indentlevel + line + "\n"
  17.                         if "</" in line:
  18.                                 indentlevel -= 1
  19.                 else:
  20.                         output += "  "*indentlevel + line + "\n"
  21.                         indentlevel -= 1
  22.         return output
  23.  
  24. print prettyxml(contents)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top