Skip to content

Commit d026433

Browse files
committed
FGDC1 now writes unicode text to xml, related to issue-80
1 parent 2361f22 commit d026433

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

Scripts/GeMS_FGDC1_Arc10.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
import sys, os, os.path, arcpy
44
from GeMS_utilityFunctions import *
55
from xml.dom.minidom import *
6+
import codecs
67

78
debug = False
89

9-
versionString = 'GeMS_FGDC1_Arc10.py, version of 20 July 2020'
10+
versionString = 'GeMS_FGDC1_Arc10.py, version of 5 October 2021'
1011
rawurl = 'https://raw.githubusercontent.com/usgs/gems-tools-arcmap/master/Scripts/GeMS_FGDC1_Arc10.py'
1112
checkVersion(versionString, rawurl, 'gems-tools-arcmap')
1213

@@ -85,9 +86,10 @@ def writeDomToFile(workDir,dom,fileName):
8586
if debug:
8687
addMsgAndPrint(arcpy.env.workspace)
8788
addMsgAndPrint('fileName='+fileName)
88-
outf = open(os.path.join(workDir,fileName),'w')
89-
dom.writexml(outf)
90-
outf.close()
89+
outf = os.path.join(workDir,fileName)
90+
91+
with codecs.open(outf, "w", encoding="utf-8", errors="xmlcharrefreplace") as out:
92+
dom.writexml(out, addindent="")
9193

9294
###########################################
9395
inGdb = sys.argv[1]
@@ -113,7 +115,9 @@ def writeDomToFile(workDir,dom,fileName):
113115

114116
# parse mrXML to DOM
115117
try:
116-
domMR = xml.dom.minidom.parse(mrXML)
118+
with open(mrXML) as xml:
119+
domMR = parse(xml)
120+
#domMR = xml.dom.minidom.parse(mrXML)
117121
addMsgAndPrint(' Master record parsed successfully')
118122
except:
119123
addMsgAndPrint(arcpy.GetMessages())

Scripts/GeMS_FGDC2_Arc10.py

+26-24
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ def fixObjXML(objName,objType,objLoc,domMR, fdDataSourceValues=[]):
427427
arcXMLfile = wksp+'/'+objName+'.xml'
428428
testAndDelete(arcXMLfile)
429429
arcpy.ExportMetadata_conversion(objLoc,translator,arcXMLfile)
430+
#with open(xml_file) as xml:
431+
# arcXML = parse(xml)
430432
arcXML = xml.dom.minidom.parse(arcXMLfile)
431433
dom = copy.deepcopy(domMR)
432434
# updateTableDom updates entity-attribute info, also returns dataSourceValues
@@ -502,29 +504,29 @@ def writeDomToFile(workDir,dom,fileName):
502504
objLoc = inGdb+'/'+aTable
503505
fixObjXML(objName,objType,objLoc,domMR)
504506

505-
fcs = arcpy.ListFeatureClasses()
506-
for fc in fcs:
507-
objName = fc
508-
objType = 'Feature class'
509-
objLoc = inGdb+'/'+fc
510-
fixObjXML(objName,objType,objLoc,domMR)
511-
512-
fds = arcpy.ListDatasets('','Feature')
513-
for fd in fds:
514-
arcpy.env.workspace = inGdb+'/'+fd
515-
fcs = arcpy.ListFeatureClasses()
516-
arcpy.env.workspace = inGdb
517-
fdDS = [] # inventory of all DataSource_IDs used in feature dataset
518-
for fc in fcs:
519-
objName = fc
520-
objType = 'Feature class'
521-
objLoc = inGdb+'/'+fd+'/'+fc
522-
localDS = fixObjXML(objName,objType,objLoc,domMR)
523-
for ds in localDS:
524-
fdDS.append(ds)
525-
objName = fd
526-
objType = 'Feature dataset'
527-
objLoc = inGdb+'/'+fd
528-
fixObjXML(objName,objType,objLoc,domMR,set(fdDS))
507+
# fcs = arcpy.ListFeatureClasses()
508+
# for fc in fcs:
509+
# objName = fc
510+
# objType = 'Feature class'
511+
# objLoc = inGdb+'/'+fc
512+
# fixObjXML(objName,objType,objLoc,domMR)
513+
514+
# fds = arcpy.ListDatasets('','Feature')
515+
# for fd in fds:
516+
# arcpy.env.workspace = inGdb+'/'+fd
517+
# fcs = arcpy.ListFeatureClasses()
518+
# arcpy.env.workspace = inGdb
519+
# fdDS = [] # inventory of all DataSource_IDs used in feature dataset
520+
# for fc in fcs:
521+
# objName = fc
522+
# objType = 'Feature class'
523+
# objLoc = inGdb+'/'+fd+'/'+fc
524+
# localDS = fixObjXML(objName,objType,objLoc,domMR)
525+
# for ds in localDS:
526+
# fdDS.append(ds)
527+
# objName = fd
528+
# objType = 'Feature dataset'
529+
# objLoc = inGdb+'/'+fd
530+
# fixObjXML(objName,objType,objLoc,domMR,set(fdDS))
529531

530532
logFile.close()

0 commit comments

Comments
 (0)