def __createTemplateFromXML(xml): """ Parses an xml string converting it to an easily parse-able python template representation: xml - a string containing an xml representation of the interface """ if isinstance(xml, minidom.Text): return xml.nodeValue.strip() (create, attributes, children) = (xml.tagName, xml.attributes, xml.childNodes) accessor = attributes.get('accessor', "") id = attributes.get('id', "") name = attributes.get('name', "") if accessor: accessor = accessor.value attributes.removeNamedItem('accessor') if id: id = id.value attributes.removeNamedItem('id') if name: name = name.value attributes.removeNamedItem('name') properties = tuple(((attribute[0], interpretFromString(attribute[1])) for attribute in attributes.items())) if children: childNodes = (__createTemplateFromXML(node) for node in children if node.__class__ in (minidom.Element, minidom.Text)) childElements = tuple(child for child in childNodes if child) else: childElements = None return Template(create, accessor, id, name, childElements, properties)
def __createDictionaryFromXML(xml): """ Parses an xml string converting it to an easily parseble dictionary representation: xml - a string containing an xml representation of the interface """ (name, attributes, children) = (xml.tagName, xml.attributes, xml.childNodes) dictionary = {'create':name} for key, value in attributes.items(): dictionary[key] = interpretFromString(value) if children: dictionary['childElements'] = [] for childElement in children: if childElement.__class__ == minidom.Element: dictionary['childElements'].append(__createDictionaryFromXML(childElement)) return dictionary
def __createDictionaryFromXML(xml): """ Parses an xml string converting it to an easily parseble dictionary representation: xml - a string containing an xml representation of the interface """ (name, attributes, children) = (xml.tagName, xml.attributes, xml.childNodes) dictionary = {'create': name} for key, value in attributes.items(): dictionary[key] = interpretFromString(value) if children: dictionary['childElements'] = [] for childElement in children: if childElement.__class__ == minidom.Element: dictionary['childElements'].append( __createDictionaryFromXML(childElement)) return dictionary