def serialize_to_xml(value):
    if value is None:
        node = etree.Element('null')
    elif isinstance(value, bool):
        node = etree.Element('literal')
        node.text = 'true' if value else 'false'
        node.attrib['type'] = 'boolean'
    elif isinstance(value, (basestring, int, float)):
        node = etree.Element('literal')
        try:
            node.text = unicode(value)
        except __HOLE__:
            # Encode as UTF-8 if ASCII string can not be encoded
            node.text = unicode(value, 'utf-8')
        node.attrib['type'] = [d[1] for d in _XML_DATATYPES if isinstance(value, d[0])][0]
    elif isinstance(value, dict):
        if '_type' in value:
            node = etree.Element('object', {'type': value['_type'], 'pk': unicode(value.get('_pk', ''))})
            del value['_type']
            del value['_pk']
            if '_url' in value:
                node.attrib['url'] = value['_url']
                del value['_url']
            if value.get('_terse'):
                node.attrib['terse'] = 'true'
                del value['_terse']
        else:
            node = etree.Element('collection', {'type': 'mapping'})
        for key in value:
            v = serialize_to_xml(value[key])
            subnode = etree.Element('item', {'key': key})
            subnode.append(v)
            node.append(subnode)
    elif isinstance(value, (list, tuple, set, frozenset)):
        for x, y in ((list, 'list'), (tuple, 'tuple')):
            if isinstance(value, x):
                node = etree.Element('collection', {'type': y})
                break
        else:
            node = etree.Element('collection', {'type': 'set'})
        for item in value:
            v = serialize_to_xml(item)
            subnode = etree.Element('item')
            subnode.append(v)
            node.append(subnode)
    else:
        node = etree.Element('unknown')

    return node
dataset/ETHPy150Open mollyproject/mollyproject/molly/utils/simplify.py/serialize_to_xml