def uuid_namer(url, **kwargs): root = etree.parse(url).getroot() x_res = root.xpath( '/gmd:MD_Metadata/gmd:fileIdentifier/gco:CharacterString', namespaces=namespaces ) uuid = "GeoNetwork-" + x_res[0].text + ".xml" return uuid
def modifier(url, **kwargs): # translate ISO19139 to ISO19115 gmi_ns = "http://www.isotc211.org/2005/gmi" etree.register_namespace("gmi",gmi_ns) new_root = etree.Element("{%s}MI_Metadata" % gmi_ns) old_root = etree.parse(url).getroot() # carry over an attributes we need [new_root.set(k,v) for k,v in old_root.attrib.items()] # carry over children [new_root.append(e) for e in old_root] return etree.tostring(new_root, encoding="UTF-8", pretty_print=True, xml_declaration=True)
def set_date_stamp(fpath): namespaces = { "gmx":"http://www.isotc211.org/2005/gmx", "gsr":"http://www.isotc211.org/2005/gsr", "gss":"http://www.isotc211.org/2005/gss", "gts":"http://www.isotc211.org/2005/gts", "xs":"http://www.w3.org/2001/XMLSchema", "gml":"http://www.opengis.net/gml/3.2", "xlink":"http://www.w3.org/1999/xlink", "xsi":"http://www.w3.org/2001/XMLSchema-instance", "gco":"http://www.isotc211.org/2005/gco", "gmd":"http://www.isotc211.org/2005/gmd", "gmi":"http://www.isotc211.org/2005/gmi", "srv":"http://www.isotc211.org/2005/srv", } # Always modify date stamp! root = etree.parse(fpath) x_res = root.xpath( 'gmd:dateStamp', namespaces=namespaces ) for dateStamp in x_res: # there should be only one - could be Date or dateTime - just delete it for i in xrange(len(dateStamp)): del dateStamp[i] dateTime = etree.SubElement(dateStamp, '{http://www.isotc211.org/2005/gco}DateTime') dateTime.text = datetime.datetime.now().isoformat() root.write(fpath)