title: Export Oracle database table as XML file using Python?
body: <p>I'm trying to export a table held within an Oracle 12c database into constituent XML files, such that each row in the Oracle table produces 1 XML file. To do this, I am using the Python 2.7 library <code>xml.etree.ElementTree</code>, but I can't see anything in the <a href="https://docs.python.org/2/library/xml.etree.elementtree.html" rel="nofollow noreferrer">documentation</a> which would allow me to do this. Essentially all I require at this point is:</p>
  
  <pre><code>import cx_Oracle
  from xml.etree import ElementTree as ET
  
  SQL = ''.join([ 'SELECT * FROM ', table_name ])
  connection = cx_Oracle.connect('username/password@database')
  cursor = connection.cursor()
  
  for i in range(num_rows):
  
      ... #code works fine up to here
  
      file_name = i
      file_path = ''.join([ 'C:\..., file_name, '.xml ])
      file = open(file_path, 'w')
      cursor.execute(SQL)
      ET.ElementTree.write(file) #This line won't work
      cursor.close()
      file.close()
  
  connection.close()
  </code></pre>
  
  <p>I know it will only be 1 line of code - I'm just really not sure what to do.</p>
  
  <p>As an added complication, I can unfortunately only use libraries native to Python 2.7 such as etree - <strong>I'm not able to download 3rd party Python libraries at work.</strong> Thanks in advance for any help or advice.</p>