if arcpy.Exists(existing_xml):
# do the conversion
arcpy.ESRITranslator_conversion (existing_xml, translator, r'\\export\outputfile.xml') # this fails if the MD is pre ArcGIS10
The Python Way is to save yourself trouble by taking the approach of instead of asking for permission, asking for forgiveness later. It sounds messy, but the approach has an elegance that (I think) is really remarkable.For example (note, totally untested code):
import os
import arcpy
from arcpy import conversion as CV
# get translator path
InstallDir = arcpy.GetInstallInfo("Desktop")["InstallDir"]
translator = os.path.join(InstallDir,r"\Metadata\Translator",
"ESRI_ISO2ISO19139.xml")
# input and output
docThing = r"C:\work\myfile.gdb\featureclass"
outXML = os.path.join(r"\\export",os.path.basename(docThing)) + ".xml"
try:
CV.ESRITranslator(docThing, translator, outXML)
except:
# export failed
try:
# perhaps this metadata just needs upgrade?
print "upgrading %s to 10..." % docThing
CV.UpgradeMetadata(docThing,"ESRIISO_TO_ARCGIS")
finally:
# in any case, if upgrade fails or not, create or update
# metadata off the dataset properties
CV.SynchronizeMetadata(docThing,"ALWAYS")
try:
# one more time try to export
CV.ESRITranslator(docThing, translator, outXML)
except:
print "Metadata export failed for " + docThing