I'm new both to this forum and Python, and I'm having trouble tracking down a solution to my problem. I'm hoping someone can offer some process-improvement advice and/or code to help get my metadata issue sorted. This is the first script I've attempted so I imagine there's a better way to do what I'm looking for.
Create a script to:
• import metadata and have it reflect the correct information about the new file • remove linkage, lineage, and copyHistory elements or text (and any other reference to location on our servers) for public sharing of file
• Python script to apply metadata based on an existing XML file using arcpy.ImportMetadata_conversion, sync enabled. • Remove elements from XML file using minidom removeChild.
# Step 4: Import metadata # polygon file arcpy.ImportMetadata_conversion ("metadatafile.xml", "FROM_ARCGIS", polyfilefull, "ENABLED") #Step 5: Remove identifying information from metadata # based on http://stackoverflow.com/questions/5699745/how-to-comment-out-an-xml-element-using-minidom-dom-implementation # added "utf-8" to avoid a whitespace error, appears to work from xml.dom import minidom polydoc = minidom.parse(polyfilefull + ".xml") for linkage in polydoc.getElementsByTagName('linkage'): linkage.parentNode.removeChild(linkage) for lineage in polydoc.getElementsByTagName('lineage'): lineage.parentNode.removeChild(lineage) for copyHistory in polydoc.getElementsByTagName('copyHistory'): copyHistory.parentNode.removeChild(copyHistory) f = open(polyfilefull + ".xml", "w") f.write(polydoc.toxml("utf-8")) f.close()
• “Linkage” reappears when metadata is viewed in Arc. • Want to update publication date based on current date
• Remove the text of the element rather than the element itself, and remove ‘sync’ from the element or • change the value of sync to FALSE.