lolamontes69

Python / pretty_xml.py uses BeautifulSoup4

Jun 8th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import bs4 as BeautifulSoup
  2.  
  3. def pretty_xml(filename):
  4.     content = open(filename)
  5.     soup=BeautifulSoup.BeautifulSoup(content)
  6.     output = soup.prettify().encode('utf-8')
  7.     outputname = filename+str('.pretty')
  8.     outputfile = open(outputname,'w')
  9.     for line in output:
  10.         try:
  11.             outputfile.write(line.encode('utf-8'))
  12.         except: pass
  13.  
  14.     outputfile.close()
  15.     print "File created as",outputname
  16.  
  17. filename = str(raw_input('Enter filename >'))
  18. pretty_xml(filename)
  19.  
  20. """  This program takes xml code and prints an output file
  21.     that is prettified using the BeautifulSoup module.
  22.     The output file has the same name as the input file
  23.     with a '.pretty' suffix added to it.
  24.     Just type in the filename and get some prettier code """
Advertisement
Add Comment
Please, Sign In to add comment