|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
writing to xml-file
Please, can someone help:
I need a script to pass some xml-data from a form and add it to an xml-file. The script I've been trying out is supposed to get the elements into its right place in the node tree, but it doesn't work. MSMXL is telling me that "parentNode is null" or object is missing. This is what the script looks like: <%@ Language=JScript%> <% var personid = Request.querystring("personid"); var comment = Request.querystring("comment"); var refnum = Request.querystring("refnum"); var bind = Request.querystring("bind"); var side = Request.querystring("side"); var xmlDoc=Server.CreateObject("Msxml2.FreeThreadedDOMDocument"); xmlDoc.async="false"; xmlDoc.load(Server.MapPath("person_comment.xml")); var nodeList = xmlDoc.getElementsByTagName("person_comments"); if (nodeList > 0){ var parentNode = nodeList(0) ; var person_commentNode = xmlDoc.createElement("person_comment"); var personidNode = xmlDoc.createElement("personid"); var commentNode = xmlDoc.createElement("comment"); var refnumNode = xmlDoc.createElement("refnum"); var bindNode = xmlDoc.createElement("bind"); var sideNode = xmlDoc.createElement("side"); personidNode.text = personid; commentNode.text = comment; refnumNode.text = refnum; bindNode.text= bind; sideNode.text = side; root.appendChild(person_commentNode); person_commentNode.appendChild(personidNode); person_commentNode.appendChild(commentNode); person_commentNode.appendChild(refnumNode); person_commentNode.appendChild(bindNode); person_commentNode.appendChild(sideNode); xmlDoc.save(Server.MapPath("person_comment.xml")); } %> The xml-file I'm writing to looks like this: <?xml version="1.0" encoding="utf-8"?> <person_comments> <person_comment><id>1</id><personid></personid><comment>tdddd</comment><refnum>6</refnum><bind></bind><side></side></person_comment> </peson_comments> I would be really happy to hear from anyone about this one. Bente |
|
#2
|
|||
|
|||
|
Two things:
I think Code:
var parentNode = nodeList(0) ; Code:
var parentNode = nodeList[0]; Also, "root" is undefined, so Code:
root.appendChild(person_commentNode); |
|
#3
|
||||
|
||||
|
Thank you for your help.
Quote:
Tried that, but nothing happened. Quote:
Yes, you're right. I meant parentNode. I also moved that line after the other five appendChild statements, but still no result. The parentNode is still null. Thanks anyway! |
|
#4
|
|||
|
|||
|
Well, you can try nodeList.item(0).
|
|
#5
|
|||
|
|||
|
I found the mistake.
xmlDoc.async="false"; should of course be xmlDoc.async=false; Thanks for the effort. I really appreciate it. bente |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > writing to xml-file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|