def get_dynamic_element(key, val):
    element = ElementTree.Element(key)
    if isinstance(val, dict):
        element.text = unicode(val.get('#text', ''))
        element.attrib = dict([(x[1:], unicode(val[x])) for x in \
                               filter(lambda x: x and x.startswith("@"), val.keys())])
    else:
        # assume it's a string. Hopefully this is valid
        element.text = unicode(val)
    return element
Gets an element from a key/value pair assumed to be pulled from
dataset/ETHPy150Open dimagi/commcare-hq/corehq/ex-submodules/casexml/apps/case/xml/generator.py/get_dynamic_element