Parse the <guest> element of the connection capabilities XML

def _parse_caps_guest(guest):
    '''
    Parse the <guest> element of the connection capabilities XML
    '''
    arch_node = guest.find('arch')
    result = {
        'os_type': guest.find('os_type').text,
        'arch': {
            'name': arch_node.get('name'),
            'machines': {},
            'domains': {}
        },
    }

    for child in arch_node:
        if child.tag == 'wordsize':
            result['arch']['wordsize'] = int(child.text)
        elif child.tag == 'emulator':
            result['arch']['emulator'] = child.text
        elif child.tag == 'machine':
            _caps_add_machine(result['arch']['machines'], child)
        elif child.tag == 'domain':
            domain_type = child.get('type')
            domain = {
                'emulator': None,
                'machines': {}
            }
            emulator_node = child.find('emulator')
            if emulator_node is not None:
                domain['emulator'] = emulator_node.text
            for machine in child.findall('machine'):
                _caps_add_machine(domain['machines'], machine)
            result['arch']['domains'][domain_type] = domain

    # Note that some features have no default and toggle attributes.
    # This may not be a perfect match, but represent them as enabled by default
    # without possibility to toggle them.
    # Some guests may also have no feature at all (xen pv for instance)
    features_nodes = guest.find('features')
    if features_nodes is not None:
        result['features'] = {child.tag: {'toggle': True if child.get('toggle') == 'yes' else False,
                                          'default': True if child.get('default') == 'no' else True}
                              for child in features_nodes}

    return result