redice
06-17-2009, 03:03 AM
Hi all,
I have been assigned to solve this asp/xml page issue, which was not written by me. The developer left, so I am left with no clue.
Since I have zero background about xml and have spent 3 days searching for answers in forums and google, here I am.
Here is the code. Based on the remarks written, it's obvious it's trying to save new nodes on top of the tree by doing some copy and replacement, which I am really confused about.
<%
dim intID, 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")
SupervisorName = Request.QueryString("SupervisorName")
id = "Auto"
if request.Form("Submit") <> "" then
objXML.async = False
'check if the file exists
blnFileExist = objXML.load(xmlpath)
if request.QueryString("id") = "" then
' if it doesn't create it, if it does then get the node count
' take note of IntID, thats the way we get the count of nodes
If blnFileExist = False Then
objXML.appendChild(objXML.createProcessingInstruction("xml","version=""1.0"""))
intID = 1
Else
objXML.Load(xmlpath)
objXMLData.Load(xmlpath)
set xmlcontents = objXMLData.DocumentElement.selectSingleNode("contents")
if objXML.childnodes(0).childnodes(0).hasChildNodes then
intID = xmlcontents.Childnodes.length + 1
else
intID = 1
end if
End If
' 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)
if i = xmlcontents.ChildNodes.length - 1 then
'Copy the last content at the bottom to the newly appended node
objXMLTop.childNodes(0).text = xmlcontent.ChildNodes.item(0).text
objXMLTop.childNodes(1).text = xmlcontent.ChildNodes.item(1).text
objXMLTop.childNodes(2).text = xmlcontent.ChildNodes.item(2).text
objXMLTop.childNodes(3).text = xmlcontent.ChildNodes.item(3).text
objXMLTop.childNodes(4).text = xmlcontent.ChildNodes.item(4).text
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(i).replaceChild objXMLv, objXMLvOld
objXML.save(xmlpath)
else
' 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)
end if
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)
else
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 = request.form("id")
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 = request.form("SupervisorName")
set objXMLvOld = objXML.childnodes(0).childnodes(0).childnodes(request.QueryString("id"))
objXML.documentElement.childnodes(0).replaceChild objXMLv, objXMLvOld
objXML.save(xmlpath)
end if
'good idea to do, saves mem
Set objXMLv = Nothing
Set objXML = Nothing
msg = "Item is saved!"
response.Redirect("adminlistcontents.asp?SupervisorName=" + SupervisorName)
end if
if request.QueryString("id") <> "" then
objXML.Load(xmlpath)
set xmlcontents = objXML.DocumentElement.selectSingleNode("contents")
set xmlcontent = xmlcontents.ChildNodes.item(request.QueryString("id"))
id = xmlcontent.ChildNodes.item(0).text
title = xmlcontent.ChildNodes.item(1).text
details = xmlcontent.ChildNodes.item(2).text
date1 = xmlcontent.ChildNodes.item(3).text
' The Supervisor login to modify is shown as the editor.
end if
%>
xml code
<aspxml>
<contents>
<Content>
<ID>246</ID>
<title>Title A</title>
<details>This is a good title</details>
<date>11/6/2009</date>
<editor>Jamie C</editor>
</Content>
<Content>
<ID>245</ID>
<title>Title B</title>
<details>Another good title</details>
<date>11/6/2009</date>
<editor>Jamie C</editor>
</Content>
</contents>
</aspxml>
I found another page written by the same programmer, it can add successfully without any error, but the new entry is at the bottom of the xml, instead of the top.
With the above example, if a new entry is to be added, ID 247 will be before 246.
I hope I have made myself clear. Right now, the error message I get is:
Microsoft VBScript runtime error '800a01a8'
Object required: 'childnodes(...).childnodes(...)'
/online/OnlineTeamBriefing/newcontent.asp, line 29
Looking forward to hearing from you. Thank you.
I have been assigned to solve this asp/xml page issue, which was not written by me. The developer left, so I am left with no clue.
Since I have zero background about xml and have spent 3 days searching for answers in forums and google, here I am.
Here is the code. Based on the remarks written, it's obvious it's trying to save new nodes on top of the tree by doing some copy and replacement, which I am really confused about.
<%
dim intID, 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")
SupervisorName = Request.QueryString("SupervisorName")
id = "Auto"
if request.Form("Submit") <> "" then
objXML.async = False
'check if the file exists
blnFileExist = objXML.load(xmlpath)
if request.QueryString("id") = "" then
' if it doesn't create it, if it does then get the node count
' take note of IntID, thats the way we get the count of nodes
If blnFileExist = False Then
objXML.appendChild(objXML.createProcessingInstruction("xml","version=""1.0"""))
intID = 1
Else
objXML.Load(xmlpath)
objXMLData.Load(xmlpath)
set xmlcontents = objXMLData.DocumentElement.selectSingleNode("contents")
if objXML.childnodes(0).childnodes(0).hasChildNodes then
intID = xmlcontents.Childnodes.length + 1
else
intID = 1
end if
End If
' 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)
if i = xmlcontents.ChildNodes.length - 1 then
'Copy the last content at the bottom to the newly appended node
objXMLTop.childNodes(0).text = xmlcontent.ChildNodes.item(0).text
objXMLTop.childNodes(1).text = xmlcontent.ChildNodes.item(1).text
objXMLTop.childNodes(2).text = xmlcontent.ChildNodes.item(2).text
objXMLTop.childNodes(3).text = xmlcontent.ChildNodes.item(3).text
objXMLTop.childNodes(4).text = xmlcontent.ChildNodes.item(4).text
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(i).replaceChild objXMLv, objXMLvOld
objXML.save(xmlpath)
else
' 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)
end if
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)
else
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 = request.form("id")
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 = request.form("SupervisorName")
set objXMLvOld = objXML.childnodes(0).childnodes(0).childnodes(request.QueryString("id"))
objXML.documentElement.childnodes(0).replaceChild objXMLv, objXMLvOld
objXML.save(xmlpath)
end if
'good idea to do, saves mem
Set objXMLv = Nothing
Set objXML = Nothing
msg = "Item is saved!"
response.Redirect("adminlistcontents.asp?SupervisorName=" + SupervisorName)
end if
if request.QueryString("id") <> "" then
objXML.Load(xmlpath)
set xmlcontents = objXML.DocumentElement.selectSingleNode("contents")
set xmlcontent = xmlcontents.ChildNodes.item(request.QueryString("id"))
id = xmlcontent.ChildNodes.item(0).text
title = xmlcontent.ChildNodes.item(1).text
details = xmlcontent.ChildNodes.item(2).text
date1 = xmlcontent.ChildNodes.item(3).text
' The Supervisor login to modify is shown as the editor.
end if
%>
xml code
<aspxml>
<contents>
<Content>
<ID>246</ID>
<title>Title A</title>
<details>This is a good title</details>
<date>11/6/2009</date>
<editor>Jamie C</editor>
</Content>
<Content>
<ID>245</ID>
<title>Title B</title>
<details>Another good title</details>
<date>11/6/2009</date>
<editor>Jamie C</editor>
</Content>
</contents>
</aspxml>
I found another page written by the same programmer, it can add successfully without any error, but the new entry is at the bottom of the xml, instead of the top.
With the above example, if a new entry is to be added, ID 247 will be before 246.
I hope I have made myself clear. Right now, the error message I get is:
Microsoft VBScript runtime error '800a01a8'
Object required: 'childnodes(...).childnodes(...)'
/online/OnlineTeamBriefing/newcontent.asp, line 29
Looking forward to hearing from you. Thank you.