I was in a flow updating metadata for feature classes within a file geodatabase. In this process I renamed and moved multiple feature classes either within a gdb or from one gdb to another. Now I am updating the Item Description using ElementTree and Python, BUT for some reason multiple feature classes are missing every xml element except "ESRI". IN particular "dataIdInfo" is what I have updated successfully many, many times. I will attach some code to show my methodology, but the issue is that multiple feature classes have no metadata basically - "refSysInfo", "mdLang", mdChar" - literally every core metadata item is missing from the xml tree save for the "ESRI" Parent (??).
1) BAD XML
2) NORMAL XML (notice dataIdInfo and everything that follows)
Here is an example of my workflow BUT it's not my problem - above screenshot is the issue - script just for context if interested.
import xml.etree.ElementTree as ET
import arcpy
import copy
# 1) get xml from fcs
fp_fcs = 'path/to/gdb/feature_class'
temp_path = copy.copy(fp_fcs)
tgt_item_md = arcpy.metadata.Metadata(fp_fcs)
fp_xml = arcpy.CreateScratchName('.xml', workspace = arcpy.env.scratchFolder)
# copy xml of feature class -- next up - update it
tgt_item_md.saveAsXML(fp_xml, 'EXACT_COPY')
# 2) Update tree with new metadata
tree = ET.parse(fp_xml)
root = tree.getroot()
# Always in xml file - until today? This will return a NONE object
dataIdInfo = root.find('dataIdInfo')
# This will fail --> "None object does not have method find"
purp = dataIdInfo.find('idPurp')
# BUT when it's working I do this:
# update purpose subelement
el = ET.SubElement(dataIdInfo, 'idPurp)
el.text = 'my new purpose text block'
# write to scratch xml
ET.dump(dataIdInfo)
tree.write(fp_xml)
# 3) Apply updated xml to orig fcs and save
# Apply to fcs
# now that xml is updated, pull new xml
src_template_md = arcpy.metadata.Metadata(fp_xml)
# add updated xml to feature class xml
tgt_item_md.copy(src_template_md)
tgt_item_md.save()
I'm hoping there is a tool/function that can update BAD to NORMAL xml - like an update gdb metadata.
Help is ABUNDANTLY APPRECIATED! Thanks...