I am trying to overwrite the default metadata stored in the service definition draft file under the "XmlDoc" element tag. The problem that i am facing is that when i overwrite it ,my file changes into the standard xml file probably because of the library and workflow that i am using for changing it. How can i do it without changing the actual structure of draft file?
Here is how i do it:
import xml.etree.ElementTree as ET
import os
import sys
import json
import arcgisscripting
import arcpy
import arcgis
from arcgis.gis import GIS
import xml.dom.minidom as DOM
import shutil
import xml.etree.ElementTree as ET
import netCDF4
import lxml.etree as et
rasterimage = r"C:\Users\arcgis\schism.crf"
output_draft = r"C:\Users\arcgis\airquality.sddraft"
service = "airquality"
con = r"C:\Users\arcgis\rasterimage.ags"
arcpy.CreateImageSDDraft(rasterimage, output_draft, service,
'FROM_CONNECTION_FILE', con, True, None, "netCDF test", "schism,netcdf")
metadata_path=r"C:\Users\arcgis\UnidataDD2MI_result.xml"
xsl_file=r"C:\Users\arcgis\MyScript.xsl"
out_file=r"C:\Users\arcgis\out.xml"
doc = et.parse(output_draft)
xsl = et.parse(xsl_file)
transform = et.XSLT(xsl)
result = transform(doc)
print(result)
result.write_output(out_file)
sys.exit(0) The xsl file looks like this:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" encoding="utf-8" indent="yes" />
<xsl:strip-space elements="*"/>
<!-- IDENTITY TRANSFORM -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!-- REPLACE XMLDoc -->
<xsl:template match="XmlDoc">
<xsl:copy>
<xsl:apply-templates select="document('UnidataDD2MI_result.xml')"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>