title: Python - Update XML row in SqlServer (TypeError: 'type' object has no attribute '__getitem__')
body: <p>I've been saving xml in a <strong>SQLServer</strong> database from python like this:</p>
  
  <pre><code>import pypyodbc as pyodbc
  import urllib
  from xml.dom.minidom import Document
  
  doc = Document()
  base = doc.createElement('PERSONA')
  doc.appendChild(base)
  entry = doc.createElement('INFORMACION')
  base.appendChild(entry)
  nombre = doc.createElement('NOMBRE')
  contenidoNombre = doc.createTextNode('Jack')
  nombre.appendChild(contenidoNombre)
  entry.appendChild(nombre)
  apellido = doc.createElement('APELLIDO')
  contenidoApellido = doc.createTextNode('Black')
  apellido.appendChild(contenidoApellido)
  entry.appendChild(apellido)
  
  print doc.toxml()
  
  cnxn = pyodbc.connect(
      'Trusted_Connection=yes;DRIVER={SQL Server};SERVER=localhost;DATABASE=HOLA;UID=sa;PWD=CPTZ@VPN-2011'
  )
  
  idPerson = 2
  
  cursor = cnxn.cursor()
  cursor.execute("INSERT INTO prueba VALUES (?, ?)", (idPerson, doc.toxml()))
  cnxn.commit()
  print("XML Guardado");
  </code></pre>
  
  <p>And this is the script for the database:</p>
  
  <pre><code>USE [HOLA]
  GO
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  CREATE TABLE [dbo].[prueba](
      [id] [int] NOT NULL,
      [xml] [xml] NULL,
   CONSTRAINT [PK_prueba] PRIMARY KEY CLUSTERED 
  (
      [id] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  
  GO
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/OYdEW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OYdEW.png" alt="enter image description here"></a></p>
  
  <p>Now, I want to update the <em>XML</em> field from <strong>Python</strong>, I've been trying this:</p>
  
  <pre><code>import pypyodbc as pyodbc
  import urllib
  from xml.dom import minidom
  from xml.dom.minidom import parse, parseString
  
  # Replace text from nodes of the xml
  def replaceText(node, newText):
      if node.firstChild.nodeType != node.TEXT_NODE:
          raise Exception("node does not contain text")
      node.firstChild.replaceWholeText(newText)  
  
  # Connection string
  cnxn = pyodbc.connect(
      'Trusted_Connection=yes;DRIVER={SQL Server};SERVER=localhost;DATABASE=TEST;UID=sa;PWD=123456'
  )
  
  idPersona = 3
  # Load the selected row
  cursor = cnxn.cursor()
  cursor.execute('SELECT id, xml FROM prueba WHERE id=?', (idPersona,))
  
  for row in cursor.fetchall():
      print row[1]
  
  # Create a xml from the result string
  xml = row[1]
  dom = parseString(xml)
  
  # Update the nodes in the XML
  node = dom.getElementsByTagName('NOMBRE')[0]
  replaceText(node, "Modificado")
  nombre = node.firstChild.nodeValue
  
  node = dom.getElementsByTagName('APELLIDO')[0]
  replaceText(node, "Modificado")
  apellido = node.firstChild.nodeValue
  
  # Show the result...
  print ("Nombre: " + nombre)
  print ("Apellido: " + apellido)
  
  # The problem is here...
  cursor = cnxn.cursor()
  cursor.execute("UPDATE prueba SET xml=? WHERE id=?", (dom, idPersona))
  cnxn.commit()
  print 'Actualizacion Realizada con Exito'
  </code></pre>
  
  <p>When the program runs the update query, It gives me the next error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "C:\Users\cnavarro\Downloads\test.py", line 44, in &lt;module&gt;
      cursor.execute("UPDATE prueba SET xml=? WHERE id=?", (dom, idPersona))
    File "build\bdist.win32\egg\pypyodbc.py", line 1470, in execute
      self._BindParams(param_types)
    File "build\bdist.win32\egg\pypyodbc.py", line 1275, in _BindParams
      if param_types[col_num][0] == 'u':
  TypeError: 'type' object has no attribute '__getitem__'
  </code></pre>
  
  <p>What am I doing wrong...?</p>