import arcpy, sys
from xml.etree.ElementTree import ElementTree
from arcpy import env
env.overwriteOutput = True
env.workspace = r"D:\Lakeland_GIS\GDB\Lakeland\Lakeland.gdb\AddPoints"
AGSHOME = arcpy.GetInstallInfo("Desktop")["InstallDir"]
translatorpath = AGSHOME + r"Metadata\Translator\ARCGIS2FGDC.xml"
xmlfile = r"U:\my docs\GIS Projects\Python\Scripts\List Metadata\working_test.xml"
# list any standalone feature classes
fcList = arcpy.ListFeatureClasses()
fcList.sort()
for fc in fcList:
arcpy.ExportMetadata_conversion(fc, translatorpath, xmlfile)
tree = ElementTree()
tree.parse(xmlfile)
spot = tree.find("idinfo/descript/purpose")
print fc
print spot.text
# list feature datasets
datasetList = arcpy.ListDatasets()
datasetList.sort()
for dataset in datasetList:
print dataset
# list feature classes inside the dataset
fcList = arcpy.ListFeatureClasses("","",dataset)
fcList.sort()
for fc in fcList:
arcpy.ExportMetadata_conversion(fc, translatorpath, xmlfile)
tree = ElementTree()
tree.parse(xmlfile)
spot = tree.find("idinfo/descript/purpose")
print " " + fc
print " " + spot.text
<?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- IdentityTransform --> <xsl:template match="/ | @* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()" /> </xsl:copy> </xsl:template> </xsl:stylesheet>
According to ESRI documentation:
"In geodatabases in Oracle and Informix, the XML columns use ArcSDE XML, which stores information as BLOBs in a series of separate tables. As such, they cannot be directly accessed with SQL."
http://resources.arcgis.com/en/help/main/10.2/index.html#/A_quick_tour_of_geodatabase_system_tables/...
As such, the XML metadata cannot be accessed directly by a simple query to the database.
(I tried to hunt for this as you have in the past.)
I suggest using a Python script/Model to fully export the metadata.
Use the XSLT Transformation tool and with an identity XSLT to extract all the metadata.
You can save the code below as a XLST document to feed into the tool.
See: http://www.usingxml.com/Transforms/XslIdentity<?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <!-- IdentityTransform --> <xsl:template match="/ | @* | node()"> <xsl:copy> <xsl:apply-templates select="@* | node()" /> </xsl:copy> </xsl:template> </xsl:stylesheet>
I want to pass a SQL command, something like Select DOCUMENTATION from gdb_items_vw, to retrieve all the information about the metadata of the layer.
But the difficulty is that this DOCUMENTATION field is CLOB type.
I found this command that seems correct:
SQL> select EXTRACT (XMLType (DOCUMENTATION), '/ metadata') as DOCUMENTATION from sde.gdb_items_vw where name = 'user_name.table_name';
... but as my sde.gdb_items_vw table is empty, the query gives me 0 selected lines!
So why this table is empty? Is that the right table to get metadata?
And some examples are available here in the doc as well. For example:
Example: Finding domain owners using SQL
String strLayer = layerName;
String connectionURL = null;
String connectionID = null;
String connectionPW = null;
String driverString = null;
connectionURL = "jdbc:oracle:thin:@server.domain:port:instance";
connectionID = "username";
connectionPW = "password";
driverString = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverString);
sqlconn = java.sql.DriverManager.getConnection(connectionURL, connectionID, connectionPW);
stmt = sqlconn.createStatement();
rset = stmt.executeQuery("SELECT uuid, documentation FROM sde.gdb_items_vw where upper(name) = '" + strLayer + "'");
rset.next();
java.io.InputStream xmlStream = rset.getBinaryStream("documentation");
if (xmlStream != null) {
URL url1 = new URL(<URL to ArcGIS2FGDC.xsl>);
InputStreamReader isr1 = new InputStreamReader(url1.openStream());
StreamSource xslSource1 = new StreamSource(isr1);
TransformerFactory tFactory1 = TransformerFactory.newInstance();
Transformer transformer1 = tFactory1.newTransformer(xslSource1);
Source schemaSource = new StreamSource(xmlStream);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
transformer1.transform(schemaSource, result);
StringReader reader2 = new StringReader(writer.toString());
writer2 = new StringWriter();
URL url = new URL(<URL to your own xsl>);
InputStreamReader isr2 = new InputStreamReader(url.openStream());
StreamSource xslSource = new StreamSource(isr2);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer2 = tFactory.newTransformer(xslSource);
transformer2.transform(new javax.xml.transform.stream.StreamSource(reader2),
new javax.xml.transform.stream.StreamResult(writer2));
}
xmlStream.close();
rset.close();
sqlconn.close();
return(writer2.toString());