Hi All,
I have a strange issue I can't seem to figure out (but seems like it should have a simple fix). I have a script that creates a table from XMLs containing metadata. The table is created fine/the script runs without error, but one field is being weird. The field appears blank when looked at in the attribute table, but if I look at it via the Select By Attributes Dialog's get unique values, the text string values show up just fine. (I attached a screenshot of the phenomenon below.
I've tried modifying the script in various ways, thinking that perhaps the the field length was too big but to no avail (although the table is in a file gdb, so there shouldn't be an issue). I've tried the code with a field length of 10-1500 and adjusted the string slice accordingly, but it still leads to the same problem of the values not being visible. I've also tried using this problematic field to calculate another, but the new field has the same problem (not visible when viewed in the attribute table but the strings are visible via the select by attributes dialog).
In case it has something to do with my script, here are a few bits of the code. Any help/suggestions would be greatly appreciated:
I have a strange issue I can't seem to figure out (but seems like it should have a simple fix). I have a script that creates a table from XMLs containing metadata. The table is created fine/the script runs without error, but one field is being weird. The field appears blank when looked at in the attribute table, but if I look at it via the Select By Attributes Dialog's get unique values, the text string values show up just fine. (I attached a screenshot of the phenomenon below.
I've tried modifying the script in various ways, thinking that perhaps the the field length was too big but to no avail (although the table is in a file gdb, so there shouldn't be an issue). I've tried the code with a field length of 10-1500 and adjusted the string slice accordingly, but it still leads to the same problem of the values not being visible. I've also tried using this problematic field to calculate another, but the new field has the same problem (not visible when viewed in the attribute table but the strings are visible via the select by attributes dialog).
In case it has something to do with my script, here are a few bits of the code. Any help/suggestions would be greatly appreciated:
Code:
import arcpy, sys, os
import xml.etree.ElementTree as ET
from os import path, chdir
from arcpy import env
env.overwriteOutput=1
env.workspace=arcpy.GetParameterAsText(0)
outputtable=arcpy.GetParameterAsText(1)
dir=os.path.dirname(outputtable)
file=os.path.basename(outputtable)
tableWS=os.path.join('in_memory',"table")
arcpy.management.CreateTable(*os.path.split(tableWS))
rcpy.AddField_management(tableWS,"XMLfile","TEXT","","",40)
arcpy.AddField_management(tableWS,"Title","TEXT","","",200)
arcpy.AddField_management(tableWS, "PCSName","TEXT","","",80)
arcpy.AddField_management(tableWS, "ProjAbstract","TEXT","","",1000)
abstracttag=arcpy.GetParameterAsText(8)
import glob #import glob module, used for finding pathnames matching a certain pattern
os.chdir(env.workspace) #set the operating system directory
print "Reading XMLs..."
arcpy.AddMessage("Reading XMLs...")
XMLS=[] #create an empty list
for files in glob.glob("*.xml"): #read the file with xml extensions.here, glob.glob returns a list of pathnames ending in .xml
XMLS.extend(glob.glob(files)) #add xml files to the empty list
for xml in XMLS: #Iterate through the list of xmls
path = xml
tree = ET.parse(path) #parses the xml into a hierarchical element tree based on the xml tags
cursor=arcpy.InsertCursor(tableWS) # create an insert cursor on the table
row=cursor.newRow() #set up the new row function
for node in tree.findall(abstracttag):
abstract=node.text
row.ProjAbstract=abstract[0:999]
tableWS2=arcpy.CreateTable_management(dir,file)
arcpy.CopyRows_management(tableWS,tableWS2