<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do I edit metadata with Python? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-do-i-edit-metadata-with-python/m-p/1058620#M61163</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I need some help if you all are able to help me. I was tasked to edit the metadata in our enterprise SQL server database for many feature classes. I tried to follow these instructions in the "Update metadata with Python scripts" section located here:&amp;nbsp;&lt;A href="https://desktop.arcgis.com/en/arcmap/10.7/manage-data/metadata/editing-metadata-for-many-arcgis-items.htm" target="_blank" rel="noopener"&gt;Edit metadata for many ArcGIS items—Help | Documentation&lt;/A&gt;&amp;nbsp;but I think I am missing some steps. I tried editing some of the code ESRI posted to better fit my needs but I am not sure I did that correctly. I am not a programmer, but I try my best.&lt;/P&gt;&lt;P&gt;I am trying to update the following fields in the ArcGIS metadata:&lt;/P&gt;&lt;P&gt;Distribution&lt;/P&gt;&lt;P&gt;&amp;gt; Distributor&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;gt;Contact information - distributor&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt; Organization's name "my Company's name goes here"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;Contact's Role "Distributor"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;gt;Contact information&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;Phone&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;gt;Voice "My Company's phone number goes here"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;Address&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;gt;Type "Physical"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;City "My city goes here"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;Administrative Area "My State goes here"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;Postal Code "My zip code goes here"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;Country "My country goes here"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;E-Mail Address "My company's email address goes here"&lt;/P&gt;&lt;P&gt;1) I am not sure how to write the code to connect to the database.&lt;/P&gt;&lt;P&gt;2) I am sure I will need to iterate through the database for each feature classes but I am not sure how to do this.&lt;/P&gt;&lt;P&gt;I am using ArcGIS Pro 2.7 if that helps. I also have access to ArcMap 10.8 but I would prefer to do this in ArcGIS Pro.&lt;/P&gt;&lt;P&gt;Below is the code I have so far. I got the tag information from looking at an exported xml file. Hope I got them right. I also commented out some on the code for testing purposes.&lt;/P&gt;&lt;P&gt;# batch update metadata for datasets in a folder&lt;/P&gt;&lt;P&gt;import os, sys&lt;BR /&gt;import arcpy&lt;BR /&gt;import xml.etree.ElementTree as ET&lt;/P&gt;&lt;P&gt;# arcpy environments&lt;BR /&gt;arcpy.env.overwriteOutput = "True"&lt;/P&gt;&lt;P&gt;# Script arguments...&lt;BR /&gt;Source_Metadata = arcpy.GetParameter(0)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Local variables&lt;BR /&gt;# new purpose text&lt;BR /&gt;newPurpose = "This is new text for an existing Purpose metadata element."&lt;BR /&gt;newCredits = "This is text for a new Credits metadata element."&lt;/P&gt;&lt;P&gt;#newcntorg = "My Company information"&lt;BR /&gt;#newcntvoice = "My Company's phone number"&lt;BR /&gt;#newaddrtype = "physical"&lt;BR /&gt;#newcity = "My City goes here"&lt;BR /&gt;#newstate = "My State goes here"&lt;BR /&gt;#newpostal = "My zip code goes here"&lt;BR /&gt;#newcountry = "My country goes here"&lt;BR /&gt;#newcntemail = "My company's email goes here"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# install location&lt;BR /&gt;dir = arcpy.GetInstallInfo("desktop")["InstallDir"]&lt;/P&gt;&lt;P&gt;# stylesheet to use&lt;BR /&gt;copy_xslt = r"{0}".format(os.path.join(dir,"C:\Program Files (x86)\ArcGIS\Desktop10.7\Metadata\Stylesheets\gpTools\exact copy of.xslt"))&lt;BR /&gt;arcpy.AddMessage("XSLT: {0}".format(copy_xslt))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;def update_metadata(root):&lt;BR /&gt;num_elements = 0&lt;/P&gt;&lt;P&gt;# modify purpose element's text&lt;BR /&gt;# there is only supposed to be one purpose element in metadata&lt;BR /&gt;# replace purpose element text if element exists&lt;BR /&gt;# if element doesn't exist, do nothing&lt;BR /&gt;purposeEls = root.findall(".//idPurp")&lt;BR /&gt;for element in purposeEls:&lt;BR /&gt;if element.text is not None:&lt;BR /&gt;element.text = newPurpose&lt;BR /&gt;num_elements += 1&lt;BR /&gt;&lt;BR /&gt;#cntorgEls = root.findall(".//idcntorg")&lt;BR /&gt;#for element in cntorgEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newcntorg&lt;BR /&gt;#num_elements += 1&lt;BR /&gt;&lt;BR /&gt;#cntvoiceEls = root.findall(".//idcntvoice")&lt;BR /&gt;#for element in cntvoiceEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newcntorg&lt;BR /&gt;#num_elements += 1&lt;BR /&gt;&lt;BR /&gt;#addrtypeEls = root.findall(".//idaddrtype")&lt;BR /&gt;#for element in addrtypeEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newaddrtype&lt;BR /&gt;#num_elements += 1&lt;/P&gt;&lt;P&gt;#cityEls = root.findall(".//idcity")&lt;BR /&gt;#for element in cityEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newcity&lt;BR /&gt;#num_elements += 1&lt;BR /&gt;&lt;BR /&gt;#stateEls = root.findall(".//idstate")&lt;BR /&gt;#for element in stateEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newstate&lt;BR /&gt;#num_elements += 1&lt;/P&gt;&lt;P&gt;#postalEls = root.findall(".//idpostal")&lt;BR /&gt;#for element in postalEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newpostal&lt;BR /&gt;#num_elements += 1&lt;BR /&gt;&lt;BR /&gt;#countryEls = root.findall(".//idcountry")&lt;BR /&gt;#for element in countryEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newcountry&lt;BR /&gt;#num_elements += 1&lt;BR /&gt;&lt;BR /&gt;#cntemailEls = root.findall(".//idcntemail")&lt;BR /&gt;#for element in cntemailEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newcntemail&lt;BR /&gt;#num_elements += 1&lt;BR /&gt;&lt;BR /&gt;# add credits element to dataIdInfo parent, if the parent exists&lt;BR /&gt;# ISO allows many dataIdInfo groups; ArcGIS generally supports only one, get the 1st&lt;BR /&gt;# ISO allows many idCredit elements: 1st on Item Description page, all on Resource Details page&lt;BR /&gt;# always append new idCredit element to 1st dataIdInfo with appropriate text&lt;BR /&gt;# existing idCredit elements remain in place&lt;BR /&gt;dataIdInfoEls = root.findall("./dataIdInfo[1]")&lt;BR /&gt;for element in dataIdInfoEls:&lt;BR /&gt;if element:&lt;BR /&gt;newCreditEl = ET.SubElement(element,"idCredit")&lt;BR /&gt;newCreditEl.text = newCredits&lt;BR /&gt;num_elements += 1&lt;/P&gt;&lt;P&gt;return num_elements&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;for item in Source_Metadata:&lt;BR /&gt;arcpy.AddMessage("Item: {0}".format(item))&lt;/P&gt;&lt;P&gt;# temporary XML file&lt;BR /&gt;xmlfile = arcpy.CreateScratchName(".xml",workspace=arcpy.env.scratchFolder)&lt;BR /&gt;#arcpy.AddMessage("Temporary XML file: {0}".format(xmlfile))&lt;BR /&gt;&lt;BR /&gt;# export xml&lt;BR /&gt;arcpy.XSLTransform_conversion(item, copy_xslt, xmlfile, "")&lt;BR /&gt;&lt;BR /&gt;# read in XML&lt;BR /&gt;tree = ET.parse(xmlfile)&lt;BR /&gt;root = tree.getroot()&lt;/P&gt;&lt;P&gt;changes = update_metadata(root)&lt;BR /&gt;#arcpy.AddMessage("number of elements updated: {0}".format(changes))&lt;BR /&gt;&lt;BR /&gt;if changes &amp;gt; 0:&lt;BR /&gt;# save modifications to XML&lt;BR /&gt;#arcpy.AddMessage("Saving changes to temporary file...")&lt;BR /&gt;tree.write(xmlfile)&lt;BR /&gt;&lt;BR /&gt;# import result back into metadata&lt;BR /&gt;arcpy.AddMessage("Saving updated metadata with the item...")&lt;BR /&gt;arcpy.MetadataImporter_conversion(xmlfile, item)&lt;BR /&gt;else:&lt;BR /&gt;arcpy.AddMessage("No changes to save")&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;arcpy.AddMessage('Finished updating metadata for all source metadata items')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all in advance!&lt;/P&gt;</description>
    <pubDate>Mon, 17 May 2021 16:54:16 GMT</pubDate>
    <dc:creator>JustinMaysHMIS</dc:creator>
    <dc:date>2021-05-17T16:54:16Z</dc:date>
    <item>
      <title>How do I edit metadata with Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-edit-metadata-with-python/m-p/1058620#M61163</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I need some help if you all are able to help me. I was tasked to edit the metadata in our enterprise SQL server database for many feature classes. I tried to follow these instructions in the "Update metadata with Python scripts" section located here:&amp;nbsp;&lt;A href="https://desktop.arcgis.com/en/arcmap/10.7/manage-data/metadata/editing-metadata-for-many-arcgis-items.htm" target="_blank" rel="noopener"&gt;Edit metadata for many ArcGIS items—Help | Documentation&lt;/A&gt;&amp;nbsp;but I think I am missing some steps. I tried editing some of the code ESRI posted to better fit my needs but I am not sure I did that correctly. I am not a programmer, but I try my best.&lt;/P&gt;&lt;P&gt;I am trying to update the following fields in the ArcGIS metadata:&lt;/P&gt;&lt;P&gt;Distribution&lt;/P&gt;&lt;P&gt;&amp;gt; Distributor&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;gt;Contact information - distributor&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt; Organization's name "my Company's name goes here"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;Contact's Role "Distributor"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;gt;Contact information&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;Phone&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;gt;Voice "My Company's phone number goes here"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;Address&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;gt;Type "Physical"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;City "My city goes here"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;Administrative Area "My State goes here"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;Postal Code "My zip code goes here"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;Country "My country goes here"&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;gt;E-Mail Address "My company's email address goes here"&lt;/P&gt;&lt;P&gt;1) I am not sure how to write the code to connect to the database.&lt;/P&gt;&lt;P&gt;2) I am sure I will need to iterate through the database for each feature classes but I am not sure how to do this.&lt;/P&gt;&lt;P&gt;I am using ArcGIS Pro 2.7 if that helps. I also have access to ArcMap 10.8 but I would prefer to do this in ArcGIS Pro.&lt;/P&gt;&lt;P&gt;Below is the code I have so far. I got the tag information from looking at an exported xml file. Hope I got them right. I also commented out some on the code for testing purposes.&lt;/P&gt;&lt;P&gt;# batch update metadata for datasets in a folder&lt;/P&gt;&lt;P&gt;import os, sys&lt;BR /&gt;import arcpy&lt;BR /&gt;import xml.etree.ElementTree as ET&lt;/P&gt;&lt;P&gt;# arcpy environments&lt;BR /&gt;arcpy.env.overwriteOutput = "True"&lt;/P&gt;&lt;P&gt;# Script arguments...&lt;BR /&gt;Source_Metadata = arcpy.GetParameter(0)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Local variables&lt;BR /&gt;# new purpose text&lt;BR /&gt;newPurpose = "This is new text for an existing Purpose metadata element."&lt;BR /&gt;newCredits = "This is text for a new Credits metadata element."&lt;/P&gt;&lt;P&gt;#newcntorg = "My Company information"&lt;BR /&gt;#newcntvoice = "My Company's phone number"&lt;BR /&gt;#newaddrtype = "physical"&lt;BR /&gt;#newcity = "My City goes here"&lt;BR /&gt;#newstate = "My State goes here"&lt;BR /&gt;#newpostal = "My zip code goes here"&lt;BR /&gt;#newcountry = "My country goes here"&lt;BR /&gt;#newcntemail = "My company's email goes here"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# install location&lt;BR /&gt;dir = arcpy.GetInstallInfo("desktop")["InstallDir"]&lt;/P&gt;&lt;P&gt;# stylesheet to use&lt;BR /&gt;copy_xslt = r"{0}".format(os.path.join(dir,"C:\Program Files (x86)\ArcGIS\Desktop10.7\Metadata\Stylesheets\gpTools\exact copy of.xslt"))&lt;BR /&gt;arcpy.AddMessage("XSLT: {0}".format(copy_xslt))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;def update_metadata(root):&lt;BR /&gt;num_elements = 0&lt;/P&gt;&lt;P&gt;# modify purpose element's text&lt;BR /&gt;# there is only supposed to be one purpose element in metadata&lt;BR /&gt;# replace purpose element text if element exists&lt;BR /&gt;# if element doesn't exist, do nothing&lt;BR /&gt;purposeEls = root.findall(".//idPurp")&lt;BR /&gt;for element in purposeEls:&lt;BR /&gt;if element.text is not None:&lt;BR /&gt;element.text = newPurpose&lt;BR /&gt;num_elements += 1&lt;BR /&gt;&lt;BR /&gt;#cntorgEls = root.findall(".//idcntorg")&lt;BR /&gt;#for element in cntorgEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newcntorg&lt;BR /&gt;#num_elements += 1&lt;BR /&gt;&lt;BR /&gt;#cntvoiceEls = root.findall(".//idcntvoice")&lt;BR /&gt;#for element in cntvoiceEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newcntorg&lt;BR /&gt;#num_elements += 1&lt;BR /&gt;&lt;BR /&gt;#addrtypeEls = root.findall(".//idaddrtype")&lt;BR /&gt;#for element in addrtypeEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newaddrtype&lt;BR /&gt;#num_elements += 1&lt;/P&gt;&lt;P&gt;#cityEls = root.findall(".//idcity")&lt;BR /&gt;#for element in cityEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newcity&lt;BR /&gt;#num_elements += 1&lt;BR /&gt;&lt;BR /&gt;#stateEls = root.findall(".//idstate")&lt;BR /&gt;#for element in stateEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newstate&lt;BR /&gt;#num_elements += 1&lt;/P&gt;&lt;P&gt;#postalEls = root.findall(".//idpostal")&lt;BR /&gt;#for element in postalEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newpostal&lt;BR /&gt;#num_elements += 1&lt;BR /&gt;&lt;BR /&gt;#countryEls = root.findall(".//idcountry")&lt;BR /&gt;#for element in countryEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newcountry&lt;BR /&gt;#num_elements += 1&lt;BR /&gt;&lt;BR /&gt;#cntemailEls = root.findall(".//idcntemail")&lt;BR /&gt;#for element in cntemailEls:&lt;BR /&gt;#if element.text is not None:&lt;BR /&gt;#element.text = newcntemail&lt;BR /&gt;#num_elements += 1&lt;BR /&gt;&lt;BR /&gt;# add credits element to dataIdInfo parent, if the parent exists&lt;BR /&gt;# ISO allows many dataIdInfo groups; ArcGIS generally supports only one, get the 1st&lt;BR /&gt;# ISO allows many idCredit elements: 1st on Item Description page, all on Resource Details page&lt;BR /&gt;# always append new idCredit element to 1st dataIdInfo with appropriate text&lt;BR /&gt;# existing idCredit elements remain in place&lt;BR /&gt;dataIdInfoEls = root.findall("./dataIdInfo[1]")&lt;BR /&gt;for element in dataIdInfoEls:&lt;BR /&gt;if element:&lt;BR /&gt;newCreditEl = ET.SubElement(element,"idCredit")&lt;BR /&gt;newCreditEl.text = newCredits&lt;BR /&gt;num_elements += 1&lt;/P&gt;&lt;P&gt;return num_elements&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;for item in Source_Metadata:&lt;BR /&gt;arcpy.AddMessage("Item: {0}".format(item))&lt;/P&gt;&lt;P&gt;# temporary XML file&lt;BR /&gt;xmlfile = arcpy.CreateScratchName(".xml",workspace=arcpy.env.scratchFolder)&lt;BR /&gt;#arcpy.AddMessage("Temporary XML file: {0}".format(xmlfile))&lt;BR /&gt;&lt;BR /&gt;# export xml&lt;BR /&gt;arcpy.XSLTransform_conversion(item, copy_xslt, xmlfile, "")&lt;BR /&gt;&lt;BR /&gt;# read in XML&lt;BR /&gt;tree = ET.parse(xmlfile)&lt;BR /&gt;root = tree.getroot()&lt;/P&gt;&lt;P&gt;changes = update_metadata(root)&lt;BR /&gt;#arcpy.AddMessage("number of elements updated: {0}".format(changes))&lt;BR /&gt;&lt;BR /&gt;if changes &amp;gt; 0:&lt;BR /&gt;# save modifications to XML&lt;BR /&gt;#arcpy.AddMessage("Saving changes to temporary file...")&lt;BR /&gt;tree.write(xmlfile)&lt;BR /&gt;&lt;BR /&gt;# import result back into metadata&lt;BR /&gt;arcpy.AddMessage("Saving updated metadata with the item...")&lt;BR /&gt;arcpy.MetadataImporter_conversion(xmlfile, item)&lt;BR /&gt;else:&lt;BR /&gt;arcpy.AddMessage("No changes to save")&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;arcpy.AddMessage('Finished updating metadata for all source metadata items')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 17 May 2021 16:54:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-edit-metadata-with-python/m-p/1058620#M61163</guid>
      <dc:creator>JustinMaysHMIS</dc:creator>
      <dc:date>2021-05-17T16:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: How do I edit metadata with Python?</title>
      <link>https://community.esri.com/t5/python-questions/how-do-i-edit-metadata-with-python/m-p/1058655#M61165</link>
      <description>&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;# stylesheet to use&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;copy_xslt = r"{0}".format(os.path.join(dir,"C:\Program Files (x86)\ArcGIS\Desktop10.7\Metadata\Stylesheets\gpTools\exact copy of.xslt"))&lt;/STRONG&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&lt;STRONG&gt;arcpy.AddMessage("XSLT: {0}".format(copy_xslt))&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;Arcgis Pro doesn't use XLSTs and I'm pretty sure the Metadata importer doesn't work in Pro either. I don't see it in the tools anyway.&amp;nbsp; &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/appendices/unavailable-tools.htm" target="_self"&gt;Check here for a list of metadata tools that are no longer suppported&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;What has worked for me is to create a generic metadata page with typical contacts, dates, usage, etc&amp;nbsp; export that to an xml.&amp;nbsp; Then I import it to a new feature class and make any adjustments as needed.&lt;/P&gt;</description>
      <pubDate>Mon, 17 May 2021 18:18:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-do-i-edit-metadata-with-python/m-p/1058655#M61165</guid>
      <dc:creator>JoeBorgione</dc:creator>
      <dc:date>2021-05-17T18:18:13Z</dc:date>
    </item>
  </channel>
</rss>

