Click to See Complete Forum and Search --> : Object required: 'childnodes(...).childnodes(...)'


redice
03-05-2010, 12:30 AM
Hi all,

I am having this error message on the following codes. I did not write this code. The original developer left the company and I am to assist on fixing this, which I have zero knowledge of.



dim id,title,details,date1
dim msg
dim SupervisorName
dim objXML, objXMLData, xmlcontents, xmlcontent, xmlcontentPre
set objXML = server.CreateObject("Microsoft.FreeThreadedXMLDOM")
set objXMLData = server.CreateObject("Microsoft.FreeThreadedXMLDOM")
id = "Auto"
SupervisorName = Request.QueryString("SupervisorName")

objXML.async = False
objXML.load(xmlpath)

' creates an element called note and under it elements that
' hold the data we want it to.
Set objXMLTop = objXML.createElement("Content")
objXMLTop.appendChild(objXML.createElement("ID"))
objXMLTop.appendChild(objXML.createElement("title"))
objXMLTop.appendChild(objXML.createElement("details"))
objXMLTop.appendChild(objXML.createElement("date"))
objXMLTop.appendChild(objXML.createElement("editor"))

Set objXMLv = objXML.createElement("Content")
objXMLv.appendChild(objXML.createElement("ID"))
objXMLv.appendChild(objXML.createElement("title"))
objXMLv.appendChild(objXML.createElement("details"))
objXMLv.appendChild(objXML.createElement("date"))
objXMLv.appendChild(objXML.createElement("editor"))

for i = xmlcontents.ChildNodes.length to 1 Step -1
set xmlcontent = xmlcontents.ChildNodes.item(xmlcontents.ChildNodes.length - 1)
set xmlcontentPre = xmlcontents.ChildNodes.item(i - 1)

' Copy the rest of the data so that the new node will appear at the top of the tree
Set objXMLv = objXML.createElement("Content")
objXMLv.appendChild(objXML.createElement("ID"))
objXMLv.appendChild(objXML.createElement("title"))
objXMLv.appendChild(objXML.createElement("details"))
objXMLv.appendChild(objXML.createElement("date"))
objXMLv.appendChild(objXML.createElement("editor"))

objXMLv.childNodes(0).text = xmlcontentPre.ChildNodes.item(0).text
objXMLv.childNodes(1).text = xmlcontentPre.ChildNodes.item(1).text
objXMLv.childNodes(2).text = xmlcontentPre.ChildNodes.item(2).text
objXMLv.childNodes(3).text = xmlcontentPre.ChildNodes.item(3).text
objXMLv.childNodes(4).text = xmlcontentPre.ChildNodes.item(4).text

set objXMLvOld = objXML.childnodes(0).childnodes(0).childnodes(i)
objXML.documentElement.childnodes(0).replaceChild objXMLv, objXMLvOld
objXML.save(xmlpath)

next

' Insert new item to the top
Set objXMLv = objXML.createElement("Content")
objXMLv.appendChild(objXML.createElement("ID"))
objXMLv.appendChild(objXML.createElement("title"))
objXMLv.appendChild(objXML.createElement("details"))
objXMLv.appendChild(objXML.createElement("date"))
objXMLv.appendChild(objXML.createElement("editor"))

objXMLv.childNodes(0).text = intID
objXMLv.childNodes(1).text = request.form("title")
objXMLv.childNodes(2).text = request.form("details")
objXMLv.childNodes(3).text = request.form("itemDate")
objXMLv.childNodes(4).text = SupervisorName

set objXMLvOld = objXML.childnodes(0).childnodes(0).childnodes(0)
objXML.documentElement.childnodes(0).replaceChild objXMLv, objXMLvOld
objXML.save(xmlpath)
' Append new added note with copied item below
objXML.documentElement.childnodes(0).appendChild(objXMLTop.cloneNode(true))
objXML.save(xmlpath)

'good idea to do, saves mem
Set objXMLv = Nothing
Set objXML = Nothing
msg = "Item is saved!"
response.Redirect("adminlistcontents.asp?SupervisorName=" + SupervisorName)




This error stops at "set objXMLvOld = objXML.childnodes(0).childnodes(0).childnodes(i)". Any idea what went wrong?

I understand that after it inserts the information into xml, it attempts to move the newly added information to the top of the xml tree so when the page display, it will display the newly added on the top.


This is the xml sample:


<aspxml>
<contents>
<Content>
<ID>2</ID>
<title>Media High</title>
<details>The Media High Sunbridge network diagram</details>
<date>06/11/2009</date>
<editor>JC</editor>
</Content>
<Content>
<ID>1</ID>
<title>GIS</title>
<details>Time to refresh your memory on a product call GIS</details>
<date>11/6/2009</date>
<editor>JC</editor>
</Content>
</contents>
</aspxml>


Please help... Thank you.