- Notifications
You must be signed in to change notification settings - Fork 362
Closed
Labels
Description
Hi,
The XML type is not supported on cx_Oracle. When I run a code like below, I get the error: AttributeError: 'cx_Oracle.OBJECT' object has no attribute 'read'
result = cursor.execute( """SELECT XMLElement("Date", hire_date) FROM hr.employees WHERE employee_id = 203""" ) for res in result: # The exception occours right here raw_xml = res[0].read()But there are simple workaround. Just use the function GETCLOBVAL:
result = cursor.execute( """SELECT XMLElement("Date", hire_date).GETCLOBVAL() FROM hr.employees WHERE employee_id = 203""" ) for res in result: import xml.etree.ElementTree as ET xml_string = res[0].read() tree = ET.fromstring(xml_string)The workaround works. But I think that would more pythonic if the cx_Oracle do this automatically:
result = cursor.execute( """SELECT XMLElement("Date", hire_date) FROM hr.employees WHERE employee_id = 203""" ) for res in result: xml = res[0].read() type(xml) # <class 'xml.etree.ElementTree.Element'>joelbarbosa