View Full Version : .setAttribute where attribute value is a variable

08-21-2004, 03:13 PM
Hi. I'm using ASP/vbscript to append elements and associated attributes to an xml file. Both the element values and attribute value come from a form. The problem i have is that i can't get the relevant form entry assigned to the attribute value. This is what i have. The relevant parts are in bold.


dim xid
dim xstatus
dim xsurname
dim xforename
dim xaddress
dim xemail
dim xhometelno
dim xmobiletelno
dim xworktelno

set xid = Request.Form("id")
set xstatus = Request.Form("status")
set xsurname = Request.Form("surname")
set xforename = Request.Form("forename")
set xaddress = Request.Form("address")
set xemail = Request.Form("email")
set xhometelno = Request.Form("hometelno")
set xmobiletelno = Request.Form("mobiletelno")
set xworktelno = Request.Form("worktelno")

Set objXML = server.CreateObject("Microsoft.XMLDOM")
objXML.async = False

set objphonebook = objXML.documentElement
set objperson = objXML.createElement ("person")
objperson.setAttribute "id", xid

the problem is in the line above. the DOM states that the method must be used in the form xxxx.setAttribute "attribute_name" "value of attribute" and the quotes must be included so when i put the variable xid as opposed to an absolute value such as "xid" it simply ignores it.
objphonebook.appendChild objperson

set objpersonstatus = objXML.createElement("status")
objperson.appendchild objpersonstatus
objpersonstatus.text = xstatus




I've also tried this:

set objphonebook = objXML.documentElement
set objperson = objXML.createElement ("person")
set Attr = objXML.createAttribute("id")
set Text = objXML.createTextNode(xid)
objphonebook.appendChild objperson

but it doesn't seem to make aby difference. Can anyone help? Thanks.