Skip to content

Instantly share code, notes, and snippets.

@alimranahmed
Last active October 29, 2017 02:15
Show Gist options
  • Save alimranahmed/553d20ea33eafb77549d44b4d7dbb504 to your computer and use it in GitHub Desktop.
Save alimranahmed/553d20ea33eafb77549d44b4d7dbb504 to your computer and use it in GitHub Desktop.
A very simple tool to decode xml. Python's Tkinter library used to build the interface. Python3^ is required.
import html
from tkinter import *
import xml.dom.minidom as dom
# author Al Imran Ahmed
# A very simple interface to decoded xml. i.e. &lttag&gt => <tag>
# requires python3^ with tkinter GUI library installed
class Application(Frame):
def decode_xml(self):
contents = self.textInput.get(1.0, END)
print('Encoded XML:\n'+contents)
decoded_xml = html.unescape(contents)
print('Decoded XML:\n'+decoded_xml)
try:
parsed_xml = dom.parseString(decoded_xml) # or dom.parse(xml_string)
pretty_xml = parsed_xml.toprettyxml()
except Exception:
print('Not valid XML')
pretty_xml = decoded_xml
self.textInput.delete(1.0, END)
self.textInput.insert(END, pretty_xml)
def createWidgets(self):
self.QUIT = Button(self)
self.QUIT["text"] = "QUIT"
self.QUIT["bg"] = "red"
self.QUIT["command"] = self.quit
self.QUIT.pack({"side": "top"})
self.decode = Button(self)
self.decode["text"] = "Decod-XML",
self.decode["command"] = self.decode_xml
self.decode.pack({"side": "top"})
self.textInput = Text(self, width=600, height=600)
self.textInput.pack({"side": "bottom"})
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
root = Tk()
app = Application(master=root)
root.minsize(900, 600)
root.wm_title('XML-Decode by Al Imran Ahmed')
app.mainloop()
root.destroy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment