We are trying to extract the feature_classes metadata and save it as csv. With the help of this code we are extracting Abstract, Title, Purpose, Spatial Ref, Extent without any hiccups. But in addition to that we need "Lineage" info and i don't see any lineage info in xml files converted using "ARCGIS2FGDC.xml" translator. But lineage details are getting exported when ARCGIS2ISO19139.xml translator is used.
The problem is, i couldn't able to extract any of the details (Abstract, Lineage, Title etc..) from the output xml translated using ARCGIS2ISO19139.xml. This is the code i am using
<SPAN class="keyword token">import</SPAN> os
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> csv
<SPAN class="keyword token">from</SPAN> xml<SPAN class="punctuation token">.</SPAN>etree<SPAN class="punctuation token">.</SPAN>ElementTree <SPAN class="keyword token">import</SPAN> ElementTree
<SPAN class="keyword token">from</SPAN> arcpy <SPAN class="keyword token">import</SPAN> env
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
<SPAN class="keyword token">def</SPAN> <SPAN class="token function">inventory_data</SPAN><SPAN class="punctuation token">(</SPAN>workspace<SPAN class="punctuation token">,</SPAN> datatypes<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> path<SPAN class="punctuation token">,</SPAN> path_names<SPAN class="punctuation token">,</SPAN> data_names <SPAN class="keyword token">in</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>Walk<SPAN class="punctuation token">(</SPAN>
workspace<SPAN class="punctuation token">,</SPAN> datatype<SPAN class="operator token">=</SPAN>datatypes<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> data_name <SPAN class="keyword token">in</SPAN> data_names<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">yield</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>path<SPAN class="punctuation token">,</SPAN> data_name<SPAN class="punctuation token">)</SPAN>
AGSHOME <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetInstallInfo<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Desktop"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"InstallDir"</SPAN><SPAN class="punctuation token">]</SPAN>
translatorpath <SPAN class="operator token">=</SPAN> AGSHOME <SPAN class="operator token">+</SPAN> <SPAN class="string token">"Metadata\\Translator\\ARCGIS2ISO19139.xml"</SPAN>
<SPAN class="comment token">#These two variables need to be updated each time this script is run on a new workspace</SPAN>
outfile <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"D:\QAQC\Metadata\GIS_Data_Inventory.csv"</SPAN>
xmlfile <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"D:\QAQC\Metadata\GIS_Data_Inventory.xml"</SPAN>
<SPAN class="keyword token">with</SPAN> open <SPAN class="punctuation token">(</SPAN>outfile<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'wb'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> csvfile<SPAN class="punctuation token">:</SPAN>
csvwriter <SPAN class="operator token">=</SPAN> csv<SPAN class="punctuation token">.</SPAN>writer<SPAN class="punctuation token">(</SPAN>csvfile<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#You need to update workspace in the line below</SPAN>
<SPAN class="keyword token">for</SPAN> feature_class <SPAN class="keyword token">in</SPAN> inventory_data<SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"D:\QAQC\Metadata\Test"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"FeatureClass"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
desc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Describe<SPAN class="punctuation token">(</SPAN>feature_class<SPAN class="punctuation token">)</SPAN>
sr <SPAN class="operator token">=</SPAN> desc<SPAN class="punctuation token">.</SPAN>spatialReference
arcpy<SPAN class="punctuation token">.</SPAN>ExportMetadata_conversion<SPAN class="punctuation token">(</SPAN>feature_class<SPAN class="punctuation token">,</SPAN> translatorpath<SPAN class="punctuation token">,</SPAN> xmlfile<SPAN class="punctuation token">)</SPAN>
tree <SPAN class="operator token">=</SPAN> ElementTree<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
tree<SPAN class="punctuation token">.</SPAN>parse<SPAN class="punctuation token">(</SPAN>xmlfile<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
title <SPAN class="operator token">=</SPAN> tree<SPAN class="punctuation token">.</SPAN>find <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"identificationInfo/MD_DataIdentification/citation/CI_Citation/title"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>text
<SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN>
title <SPAN class="operator token">=</SPAN> <SPAN class="string token">"No Title"</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
abstract <SPAN class="operator token">=</SPAN> tree<SPAN class="punctuation token">.</SPAN>find <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"identificationInfo/MD_DataIdentification/abstract"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>text
<SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN>
abstract <SPAN class="operator token">=</SPAN> <SPAN class="string token">"No Abstract"</SPAN>
<SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN>
lineage <SPAN class="operator token">=</SPAN> tree<SPAN class="punctuation token">.</SPAN>find <SPAN class="punctuation token">(</SPAN><SPAN class="string token">"dataQualityInfo/DQ_DataQuality/lineage/LI_Lineage/statement"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>text
<SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN>
lineage <SPAN class="operator token">=</SPAN> <SPAN class="string token">"No Lineage"</SPAN>
csvwriter<SPAN class="punctuation token">.</SPAN>writerow<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">[</SPAN>desc<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>encode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'utf-8'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> desc<SPAN class="punctuation token">.</SPAN>file<SPAN class="punctuation token">.</SPAN>encode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'utf-8'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> desc<SPAN class="punctuation token">.</SPAN>dataType<SPAN class="punctuation token">.</SPAN>encode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'utf-8'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">.</SPAN>encode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'utf-8'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> purpose<SPAN class="punctuation token">.</SPAN>encode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'utf-8'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> title<SPAN class="punctuation token">.</SPAN>encode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'utf-8'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> abstract<SPAN class="punctuation token">.</SPAN>encode<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'utf-8'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">except</SPAN> Exception<SPAN class="punctuation token">:</SPAN>
e <SPAN class="operator token">=</SPAN> sys<SPAN class="punctuation token">.</SPAN>exc_info<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>e<SPAN class="punctuation token">.</SPAN>args<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
<SPAN class="" style="color: #303336; border: 0px; font-size: 13px; margin: 0px;"><SPAN style="color: #242729; background-color: rgba(248, 248, 248, 0.6);">All i am getting in the output csv is "No Title, No Abstract, No Lineage". But the output xml file has these parameters (image attached below).</SPAN>
<IMG __jive_id="296563" alt="" class="image-1 jive-image" src="https://us.v-cdn.net/6038851/uploads/legacyfs/online/296563_T0CHM.png" style="width: 786px; height: 408px;" />
</SPAN>