The following attached script works as a script tool. I get the error when I try to run it from IDLE or the command line... apparently there is something in the environment that is messing me up. I'm running 10.0 SP 2 on XP 64.import sys, os, arcpy
def getMetadataText(Dataset,Element="dataIdInfo/idPurp"):
"""Extracts metadata contents from ArcGIS metadata
arguments
Dataset - Path to an ArcGIS dataset
Element - XML path in ArcGIS metadata.
Default: "metadata/dataIDInfo/idPurp" ("Summary")
"""
from xml.etree.ElementTree import ElementTree
try:
# Get arcgis to fgdc translator path
ARCGISHOME = arcpy.GetInstallInfo("desktop")["InstallDir"]
XSLT = os.path.normpath(os.path.join(
ARCGISHOME,
"Metadata/Stylesheets/gpTools/exact copy of.xslt"))
xmlTemp = os.path.join(os.environ["TEMP"],"xx_xmltemp.xml")
# export the metadata to xml
arcpy.env.overwriteOutput = True
arcpy.XSLTransform_conversion(Dataset,XSLT,xmlTemp)
# parse out Description element from ArcGIS 10 metadata
tree = ElementTree() # make an ElementTree object
tree.parse(xmlTemp) # read the xml into the ElementTree
Data = tree.find(Element) # find whatever tag you want
del tree
arcpy.Delete_management(xmlTemp)
return Data.text # return the contents as text
except Exception, xmsg:
raise Exception, str(xmsg)
# You could put a loop here around this to print out Summary for a list of datasets
dataset = r"E:\work\work.gdb\BeetleSprayArea.shp"
text = getMetadataText(dataset)
arcpy.AddMessage(text)