import os for aFile in os.listdir(r"C:\Path\To\Data"): if aFile.lower().endswith(".xml"): print aFile #Do stuff to xml files
Nice solution FLBB! Does it work when you open that file in ArcMap?
This should find all xml documents in a given directory.import os for aFile in os.listdir(r"C:\Path\To\Data"): if aFile.lower().endswith(".xml"): print aFile #Do stuff to xml files
from xml.etree import ElementTree as et import os workspace = r"C:\test" for dirpath, dirnames, filenames in os.walk(workspace): for filename in filenames: if filename.lower().endswith('.xml'): tree = et.parse(os.path.join(dirpath, filename)) targetTag=tree.find('.//IsNullable') if targetTag is not None: targetTag.text = 'false' else: print "No IsNullable tag was NOT found in: "+filename tree.write(os.path.join(dirpath,filename))
Hello FLBB,
I changed you if statement. This one will skip files like about.xmlfiles.txt (which is possible). It will also be case insensitive (accepting both '.xml' and '.XML' files).
I think you also need an if statement to see if 'IsNullable' actually appears in the xml file.from xml.etree import ElementTree as et import os workspace = r"C:\test" for dirpath, dirnames, filenames in os.walk(workspace): for filename in filenames: if filename.lower().endswith('.xml'): tree = et.parse(os.path.join(dirpath, filename)) targetTag=tree.find('.//IsNullable') if targetTag is not None: targetTag.text = 'false' else: print "No IsNullable tag was NOT found in: "+filename tree.write(os.path.join(dirpath,filename))
I not 100% confident this methodology will actually change the Nullable field property. I worried that you are only changing the metadata and the actual field property (in the '.dbf') is not changing. Can you actually put null values into a field of one of the shapefiles you have modified?
Let be know how it goes!