def get(dict_tree,ns=None): ''' Returns the file section from dict tree :param dict_tree: :param ns: ''' if ns is None: ns = '{http://www.loc.gov/METS/}' else: ns = ns['mets'] file_sec = xml_tools.getSubTree(dict_tree=dict_tree, ns=ns, elem_name='fileSec') return file_sec
def getLogicalStructMap(dict_tree,ns=None): ''' Returns the logical structMap sub tree from dict_tree :param dict_tree: :param ns: ''' if ns is None: ns = '{http://www.loc.gov/METS/}' else: ns = ns['mets'] log_struct_map_dict = xml_tools.getSubTree(dict_tree=dict_tree, ns=ns, elem_name='structMap', elem_attrib_key='TYPE', elem_attrib_val='LOGICAL') return log_struct_map_dict
def getFirstDmdLogByDocType(dict_tree,doc_type): log_doc_struct = getLogicalStructMap(dict_tree) ns = '{http://www.loc.gov/METS/}' dmdlog_id_key = '@DMDID' doc_type_trees = xml_tools.getSubTree(log_doc_struct, ns=ns, elem_name='div', elem_attrib_key='TYPE', elem_attrib_val = doc_type) if isinstance(doc_type_trees,list): if len(doc_type_trees) > 1: for dmd in doc_type_trees: if isinstance(dmd,dict) and dmdlog_id_key in dmd: return dmd[dmdlog_id_key] elif isinstance(doc_type_trees,dict): if dmdlog_id_key in doc_type_trees: return doc_type_trees[dmdlog_id_key] else: return None