def convert_dict(obj, ids, parent, attr_type, item_func, cdata):
    """Converts a dict into an XML string."""
    LOG.info('Inside convert_dict(): obj type is: "%s", obj="%s"' % (
        type(obj).__name__, unicode_me(obj))
    )
    output = []
    addline = output.append
    
    item_name = item_func(parent)
    
    for key, val in obj.items():
        LOG.info('Looping inside convert_dict(): key="%s", val="%s", type(val)="%s"' % (
            unicode_me(key), unicode_me(val), type(val).__name__)
        )

        attr = {} if not ids else {'id': '%s' % (get_unique_id(parent)) }

        key, attr = make_valid_xml_name(key, attr)

        if isinstance(val, numbers.Number) or type(val) in (str, unicode):
            addline(convert_kv(key, val, attr_type, attr, cdata))

        elif hasattr(val, 'isoformat'): # datetime
            addline(convert_kv(key, val.isoformat(), attr_type, attr, cdata))

        elif type(val) == bool:
            addline(convert_bool(key, val, attr_type, attr, cdata))

        elif isinstance(val, dict):
            if attr_type:
                attr['type'] = get_xml_type(val)
            addline('<%s%s>%s</%s>' % (
                key, make_attrstring(attr), 
                convert_dict(val, ids, key, attr_type, item_func, cdata), 
                key
                )
            )

        elif isinstance(val, collections.Iterable):
            if attr_type:
                attr['type'] = get_xml_type(val)
            addline('<%s%s>%s</%s>' % (
                key, 
                make_attrstring(attr), 
                convert_list(val, ids, key, attr_type, item_func, cdata), 
                key
                )
            )

        elif val is None:
            addline(convert_none(key, val, attr_type, attr, cdata))

        else:
            raise TypeError('Unsupported data type: %s (%s)' % (
                val, type(val).__name__)
            )

    return ''.join(output)
def convert_dict ( obj , ids , parent , attr_type , item_func , cdata ) : LOG . info ( 'Inside convert_dict(): obj type is: "%s", obj="%s"' % ( type ( obj ) . __name__ , unicode_me ( obj ) ) ) output = [ ] addline = output . append item_name = item_func ( parent ) for key , val in obj . items ( ) : LOG . info ( 'Looping inside convert_dict(): key="%s", val="%s", type(val)="%s"' % ( unicode_me ( key ) , unicode_me ( val ) , type ( val ) . __name__ ) ) attr = { } if not ids else { 'id' : '%s' % ( get_unique_id ( parent ) ) } key , attr = make_valid_xml_name ( key , attr ) if isinstance ( val , numbers . Number ) or type ( val ) in ( str , unicode ) : addline ( convert_kv ( key , val , attr_type , attr , cdata ) ) elif hasattr ( val , 'isoformat' ) : addline ( convert_kv ( key , val . isoformat ( ) , attr_type , attr , cdata ) ) elif type ( val ) == bool : addline ( convert_bool ( key , val , attr_type , attr , cdata ) ) elif isinstance ( val , dict ) : if attr_type : attr [ 'type' ] = get_xml_type ( val ) addline ( '<%s%s>%s</%s>' % ( key , make_attrstring ( attr ) , convert_dict ( val , ids , key , attr_type , item_func , cdata ) , key ) ) elif isinstance ( val , collections . Iterable ) : if attr_type : attr [ 'type' ] = get_xml_type ( val ) addline ( '<%s%s>%s</%s>' % ( key , make_attrstring ( attr ) , convert_list ( val , ids , key , attr_type , item_func , cdata ) , key ) ) elif val is None : addline ( convert_none ( key , val , attr_type , attr , cdata ) ) else : raise TypeError ( 'Unsupported data type: %s (%s)' % ( val , type ( val ) . __name__ ) ) return '' . join ( output )
Converts a dict into an XML string.