Skip to content

Instantly share code, notes, and snippets.

@jesse1981
Created May 8, 2013 06:42
Show Gist options
  • Save jesse1981/5538670 to your computer and use it in GitHub Desktop.
Save jesse1981/5538670 to your computer and use it in GitHub Desktop.
ASP XML search, update, delete example
Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.async = false
xmlDoc.load("filename.xml")
' See if given id exists
Dim idExists, currParentNode
idExists = false
Set objNodeList = xmlDoc.selectNodes("/events/event/id")
For each x in objNodeList
if x.text = Request.querystring("id") Then
idExists = true
' update this node
set currParentNode = x.parentNode
if Request.querystring("delete") <> "1" then
currParentNode.childNodes.Item(1).text = Request.querystring("title")
currParentNode.childNodes.Item(2).text = Request.querystring("start")
currParentNode.childNodes.Item(3).text = Request.querystring("end")
currParentNode.childNodes.Item(4).text = Request.querystring("allDay")
currParentNode.childNodes.Item(5).text = Request.querystring("type")
currParentNode.childNodes.Item(6).text = Request.querystring("desc")
else
Set objRoot = xmlDoc.documentElement
Set objExNode = objRoot.removeChild(currParentNode)
end if
exit for
end if
Next
if idExists = false and Request.querystring("delete") <> "1" Then
Dim objEventNode, objChildNode
Set objEventNode = xmlDoc.createElement("event")
xmlDoc.documentElement.AppendChild objEventNode
Set objChildNode = xmlDoc.createElement("id")
objChildNode.Text = Request.querystring("id")
objEventNode.AppendChild objChildNode
Set objChildNode = xmlDoc.createElement("title")
objChildNode.Text = Request.querystring("title")
objEventNode.AppendChild objChildNode
Set objChildNode = xmlDoc.createElement("start")
objChildNode.Text = Request.querystring("start")
objEventNode.AppendChild objChildNode
Set objChildNode = xmlDoc.createElement("end")
objChildNode.Text = Request.querystring("end")
objEventNode.AppendChild objChildNode
Set objChildNode = xmlDoc.createElement("allDay")
objChildNode.Text = Request.querystring("allDay")
objEventNode.AppendChild objChildNode
Set objChildNode = xmlDoc.createElement("type")
objChildNode.Text = Request.querystring("type")
objEventNode.AppendChild objChildNode
Set objChildNode = xmlDoc.createElement("description")
objChildNode.Text = Request.querystring("desc")
objEventNode.AppendChild objChildNode
End if
xmlDoc.save("filename.xml")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment