def xml2dict(tag): r = {} #value # tag.text is None, for empty tags. if tag.text is not None: v = tag.text.strip() r['_value'] = v #attributes if tag.keys(): r['_attributes'] = {} for k in tag.keys(): _k = remove_ns(k) _k = camelcase_to_underscore(_k) r['_attributes'][_k] = tag.get(k) for child in tag.getchildren(): ctag = remove_ns(child.tag) ctag = camelcase_to_underscore(ctag) #assuming every child is potentially a list l = r.get(ctag, []) l.append(xml2dict(child)) r[ctag] = l return r
def _attributestring(attrdict): ss = [] for key, value in attrdict.iteritems(): s = "%s = (\"%s\")" % (remove_ns(key), "\", \"".join(value)) ss.append(s) return "\r\n\r\n".join(ss)
def _attributestring(attrdict): ss = [] for key, value in attrdict.iteritems(): s = '%s = ("%s")' % (remove_ns(key), '", "'.join(value)) ss.append(s) return "\r\n\r\n".join(ss)