Original User: iggzI have a script that uses an Update Cursor to update a BLOB field with XML if certain criteria are met.
from lxml import etree
import arcpy
data = open("C:/data.txt", "r").readlines()
with arcpy.da.Editor(workspace) as edit:
with arcpy.da.UpdateCursor(Point, ["ID", "Blob"]) as cursor:
for row in cursor:
root = etree.Element("Root")
for line in data:
line_split = line.split("|")
if line_split[0] == str(row[0]):
one = etree.SubElement(root, "one")
two = etree.SubElement(one, "two").text = "two"
three = etree.SubElement(one, "three").text = "three"
four = etree.SubElement(one, "four").text = "four"
five = etree.SubElement(one, "five").text = "five"
six = etree.SubElement(one, "six").text = "six"
seven = etree.SubElement(one, "seven").text = "seven"
eight = etree.SubElement(one, "eight").text = "eight"
nine = etree.SubElement(one, "nine").text = "nine"
ten = etree.SubElement(one, "ten").text = "ten"
eleven = etree.SubElement(one, "eleven").text = "eleven"
twelve = etree.SubElement(one, "twelve").text = "twelve"
thirteen = etree.SubElement(one, "thirteen")
fourteen = etree.SubElement(one, "fourteen").text = "fourteen"
fifteen = etree.SubElement(one, "fifteen")
data = bytearray(etree.tostring(root, encoding='UTF-8', pretty_print=True), "UTF-8")
#The XML in this file shows correctly
open("C:/XML" + os.sep + str(ID) + ".txt", "w").write(data)
row[1] = data
cursor.updateRow(row)
Then I read the BLOB field:with arcpy.da.SearchCursor(Point, ["OBJECTID", "Blob"]) as cursor:
for row in cursor:
fileName = row[0]
binaryRep = row[1]
open("C:/XML" + os.sep + str(fileName) + ".xml", 'wb').write(binaryRep.tobytes())
And when I view the XML from the BLOB field it's all messed up like this:[ATTACH=CONFIG]32437[/ATTACH]But when I view the text file I also created right before row[1] = data, the XML is correct:[ATTACH=CONFIG]32438[/ATTACH]Anyone know where I'm going wrong here?PS-What can I buy with all my points?