Hi,
I'm working in ArcGIS Pro 3.3.0.
I have a script that updates an SDE feature class and then I want to update the publication date in the metadata. This is not part of the common metadata properties so it's not directly accessible from a metadata object properties.
I'm using the ISO19139 metadata standard.
My algorithm is:
My code is:
import xml.etree.ElementTree as ET
from arcpy import metadata as md
import datetime
item = r'D:\Projects\WCG General\Python 2 to 3\DOH_HealthFacilities.gdb\DOH_Facilities_AllHealthSites'
CurrentDate = datetime.datetime.now().strftime("%Y-%m-%d")
currentXMLPath = r'D:\Projects\WCG General\Python 2 to 3\temp.xml'
newXMLPath = r'D:\Projects\WCG General\Python 2 to 3\temp_updated.xml'
# get the item's metadata xml
item_md = md.Metadata(item)
metadata_xml_string = item_md.xml
# export item's metadata
item_md.exportMetadata(outputPath=currentXMLPath,
metadata_export_option='ISO19139')
# create an ElementTree object and get its root
tree = ET.parse(currentXMLPath)
root = tree.getroot()
# check that the correct element exists
# root[10][0][0][0][2][0][1][0].text must be = 'publication'
# root[10][0][0][0][2][0][0][0] is the field that must be set
# set the value of the publication date to the current date
if root[10][0][0][0][2][0][1][0].text == 'publication':
root[10][0][0][0][2][0][0][0].text = CurrentDate
# save the changes to the the new XML file
tree.write(newXMLPath)
# import the new XML to the metadata object
item_md.importMetadata(sourceUri=newXMLPath,
metadata_import_option='ISO19139')
Everything works fine until the last step, when I get an error