html and xml

Libraries

Pretty Print

>>> from xml.dom.minidom import parseString
>>> s = parseString('<myxml>Some data<empty/> some more data</myxml>')
>>> s.toprettyxml('  ')
u'<?xml version="1.0" ?>\n<myxml>\n  Some data\n  <empty/>\n   some more data\n</myxml>\n'

Quote/Unquote

>>> import urllib
>>> t = '<?xml version="1.0" encoding="utf-8"?>'
>>> urllib.quote(t)
'%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E'
>>> urllib.unquote(t)
'<?xml version="1.0" encoding="utf-8"?>'
>>> import urllib
>>> urllib.quote_plus('Vale of Glamorgan & Cardiff')
'Vale+of+Glamorgan+%26+Cardiff'