class XmlElement(object): def __init__(self, typeName, content = None, attributes = None): if content == None: content = [] if attributes == None: attributes = {} self.content = content self.attributes = attributes self.elementName = typeName def attributesAsXML(self): result = "" for a in self.attributes: result = result + " %s=\"%s\"" % (a, self.attributes[a]) return result def asXML(self): result = "<%s" % self.elementName if self.attributes: result = result + self.attributesAsXML() if not self.content: return result + "/>" else: result = result + ">" for c in self.contents: result = result + c.asXML() return result + "" % (self.elementName)