[XML-SIG] setAttribute DOM question-newbie
Guy Robinson
ohbehave@ihug.co.nz
Thu, 15 Nov 2001 10:23:20 +1300
Hello,
Trying to create a ODBC table -> xml ->(eventually) 4SS script and having
the following problem with setattribute. I would like each field value to be
an elements attribute but I can't get
new_elem.setAttribute(QryAttrName[i] ,row[i] )
to work .I can't see what's wrong with it (see complete code below).
The traceback is:
new_elem.setAttribute(QryAttrName[i] ,row[i] )
File "C:\PYTHON21\_xmlplus\dom\Element.py", line 98, in setAttribute
raise SyntaxErr()
xml.dom.SyntaxErr: Specified string is invalid or illegal
What don't I understand? TIA
Guy
import dbi , odbc
from xml.dom import implementation
import xml.dom.ext
import os, string, time
doc = implementation.createDocument(None,'revit',None)
doc_elem = doc.documentElement
startt = time.time()
DbCon = odbc.odbc('testrevit')
DbCur = DbCon.cursor()
DbCur.execute('select * from products')
QryAttrName = map(lambda dbq: dbq[0], DbCur.description)
DbRec = DbCur.fetchall()
for row in DbRec:
new_elem = doc.createElement( 'item')
for i in range(len(row)):
new_elem.setAttribute(QryAttrName[i] ,row[i] ) #<------
print QryAttrName[i], "=", row[i]
doc_elem.appendChild(new_elem)
xml.dom.ext.PrettyPrint(doc)
print time.time() - startt