fdutils/xml.py
def retrieve_xml_elements(filename, xpath, dict_of_tags, normalize_path=None, name_attribute='IRTaskGroupName'):
    """ retrieves XML values from a simple xml document given a set of tags that we want the value from

    :param filename:
    :param xpath:
    :param dict_of_tags:
    :return:
    """
    ret = []
    try:
        with open(filename) as xml:
            tree = parse_xml(xml)

            try:
                # get root to get metadata information for name or if not found use the filename
                name = tree.get(name_attribute) or os.path.splitext(os.path.basename(filename))[0]
            except:
                name = ""

            # get information
            for task in tree.findall(xpath):
                # init values
                values = dict([(k, None) for k in dict_of_tags.values()])
                for e in task.iter():
                    if e.tag in dict_of_tags:
                        data = e.text.strip() if e.text else ""
                        if isinstance(dict_of_tags[e.tag], tuple):
                            if dict_of_tags[e.tag][1]:
                                values[dict_of_tags[e.tag][0]] = normalize_path(data) if data else ""
                            else:
                                elem = e.findall(dict_of_tags[e.tag][2])
                                values[dict_of_tags[e.tag][0]] = elem[0].get(dict_of_tags[e.tag][3]) if elem else None
                        else:
                            values[dict_of_tags[e.tag]] = data
                ret.append(values)

        return ret, name
    except IOError as e:
        raise IOError(e.args + (filename, ))
 retrieves XML values from a simple xml document given a set of tags that we want the value from

    :param filename:
    :param xpath:
    :param dict_of_tags:
    :return:
    
retrieves XML values from a simple xml document given a set of tags that we want the value from
retrieves XML values from a simple xml document given a set of tags that we want the value from
def retrieve_xml_elements(filename, xpath, dict_of_tags, normalize_path=None, name_attribute='IRTaskGroupName'):
    ret = []
    try:
        with open(filename) as xml:
            tree = parse_xml(xml)
            try:
                name = tree.get(name_attribute) or os.path.splitext(os.path.basename(filename))[0]
            except:
                name = ""
            for task in tree.findall(xpath):
                values = dict([(k, None) for k in dict_of_tags.values()])
                for e in task.iter():
                    if e.tag in dict_of_tags:
                        data = e.text.strip() if e.text else ""
                        if isinstance(dict_of_tags[e.tag], tuple):
                            if dict_of_tags[e.tag][1]:
                                values[dict_of_tags[e.tag][0]] = normalize_path(data) if data else ""
                            else:
                                elem = e.findall(dict_of_tags[e.tag][2])
                                values[dict_of_tags[e.tag][0]] = elem[0].get(dict_of_tags[e.tag][3]) if elem else None
                        else:
                            values[dict_of_tags[e.tag]] = data
                ret.append(values)
        return ret, name
    except IOError as e:
        raise IOError(e.args + (filename, ))
def retrieve_xml_elements ( filename , xpath , dict_of_tags , normalize_path = None , name_attribute = 'IRTaskGroupName' ) : ret = [ ] try : with open ( filename ) as xml : tree = parse_xml ( xml ) try : name = tree . get ( name_attribute ) or os . path . splitext ( os . path . basename ( filename ) ) [ 0 ] except : name = "" for task in tree . findall ( xpath ) : values = dict ( [ ( k , None ) for k in dict_of_tags . values ( ) ] ) for e in task . iter ( ) : if e . tag in dict_of_tags : data = e . text . strip ( ) if e . text else "" if isinstance ( dict_of_tags [ e . tag ] , tuple ) : if dict_of_tags [ e . tag ] [ 1 ] : values [ dict_of_tags [ e . tag ] [ 0 ] ] = normalize_path ( data ) if data else "" else : elem = e . findall ( dict_of_tags [ e . tag ] [ 2 ] ) values [ dict_of_tags [ e . tag ] [ 0 ] ] = elem [ 0 ] . get ( dict_of_tags [ e . tag ] [ 3 ] ) if elem else None else : values [ dict_of_tags [ e . tag ] ] = data ret . append ( values ) return ret , name except IOError as e : raise IOError ( e . args + ( filename , ) )
retrieves XML values from a simple xml document given a set of tags that we want the value from
retrieves XML values from a simple xml document given a set of tags that we want the value from
""" retrieves XML values from a simple xml document given a set of tags that we want the value from

    :param filename:
    :param xpath:
    :param dict_of_tags:
    :return:
    """ # get root to get metadata information for name or if not found use the filename # get information # init values
None
filename
None
xpath
None
dict_of_tags
None
normalize_path
name_attribute