wanye
09-18-2002, 03:33 AM
hi all, currently the asp script below shows update,edit delete functions of user input to the form..but theres no add function so i tried declaring a adddetails function but there seems to be some problems with it which i dunno how to debug. So how to declare a adddetail function correctly that allows u to add new elements to the xml file through the asp ..??
the script is as follows:
<%
'-------------------------------------------------------------------
'This function accepts three paramters:
'strXMLFile - The XML file that you wish to use
'strXSLFile - The XSL stylesheet that will transform the XML file
'strEMail - The E-Mail address of the contact that you wish to delete
'-------------------------------------------------------------------
Function deleteDetail(strXMLFile, strXSLFile, strEMail)
'Declare local variables.
Dim objDom
Dim objRoot
Dim objNode
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = false
objXML.load strXMLFile
Set objRoot = objXML.documentElement
Set objNode = objRoot.SelectSingleNode("contact[field/field_value='" & strEMail & "']")
objRoot.removeChild(objNode)
objXML.save strXMLFile
loadXMLFile strXMLFile,strXSLFile
End Function
Function addDetail(strXMLFile, strXSLFile, strEMail)
'Declare local variables.
Dim objDom
Dim objRoot
Dim objNode
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = false
objXML.load strXMLFile
Set objRoot = objXML.documentElement
Set objNode = objRoot.SelectSingleNode("contact[field/field_value='" & strEMail & "']")
objRoot.addChild(objNode)
objXML.save strXMLFile
loadXMLFile strXMLFile,strXSLFile
End Function
'-------------------------------------------------------------------
'This function accepts three paramters:
'strXMLFile - The XML file that you wish to view
'strXSLFile - The XSL stylesheet that will transform the XML file
'strEMail - The E-Mail address of the contact that you wish to view
'-------------------------------------------------------------------
Function updateDetail(strXMLFile, strXSLFile, strEMail)
Dim objDom
Dim objRoot
Dim objContact
Dim objField
Dim strNewEMail
strNewEMail = Request.Form("email")
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = false
objXML.load strXMLFile
Set objRoot = objXML.documentElement
Set objContact = objRoot.SelectSingleNode("contact[field/field_value='" & strEMail & "']")
For each objItem in Request.Form
Set objField = objContact.selectSingleNode("field[@id='" & objItem & "']/field_value")
objField.text = Request.Form(objItem)
Next
objXML.save strXMLFile
viewDetail strXMLFile, strXSLFile, strNewEMail
End Function
'-------------------------------------------------------------------
'This function accepts three paramters:
'strXMLFile - The XML file that you wish to view
'strXSLFile - The XSL stylesheet that will transform the XML file
'strEMail - The E-Mail address of the contact that you wish to view
'-------------------------------------------------------------------
Function viewDetail(strXMLFile, strXSLFile, strEMail)
Dim objXML
Dim objNode
Dim objXSL
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = false
objXML.load(strXMLFile)
Set objNode = objXML.SelectSingleNode("rolodex/contact[field/field_value='" & strEMail & "']")
set objXSL = Server.CreateObject("Microsoft.XMLDOM")
objXSL.async = false
objXSL.load(strXSLFile)
Response.Write(objNode.transformNode(objXSL))
End Function
'-------------------------------------------------------------------
'This function accepts two paramters:
'strXMLFile - The XML file that you wish to view
'strXSLFile - The XSL stylesheet that will transform the XML file
'-------------------------------------------------------------------
Function loadXMLFile(strXMLFile, strXSLFile)
Dim objXML
Dim objXSL
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = false
objXML.load(strXMLFile)
set objXSL = Server.CreateObject("Microsoft.XMLDOM")
objXSL.async = false
objXSL.load(strXSLFile)
Response.Write(objXML.transformNode(objXSL))
End Function
Dim strMode
Dim strEMail
strMode = Request.QueryString("mode")
strEMail = Request.QueryString("email")
Select Case strMode
Case "viewdetail"
viewDetail server.MapPath("rolodex6.xml"), server.MapPath("viewdetail.xsl"), strEMail
Case "editdetail"
viewDetail server.MapPath("rolodex6.xml"), server.MapPath("editdetail.xsl"), strEMail
Case "updatedetail"
updateDetail server.MapPath("rolodex6.xml"), server.MapPath("viewdetail.xsl"), strEMail
Case "deletedetail"
deleteDetail server.MapPath("rolodex6.xml"), server.MapPath("rolodex6.xsl"), strEMail
Case "addDetail"
addDetail server.MapPath("rolodex6.xml"), server.MapPath("rolodex6.xsl"), strEMail
Case Else
loadXMLFile server.MapPath("rolodex6.xml"), server.MapPath("rolodex6.xsl")
End Select
%>
the script is as follows:
<%
'-------------------------------------------------------------------
'This function accepts three paramters:
'strXMLFile - The XML file that you wish to use
'strXSLFile - The XSL stylesheet that will transform the XML file
'strEMail - The E-Mail address of the contact that you wish to delete
'-------------------------------------------------------------------
Function deleteDetail(strXMLFile, strXSLFile, strEMail)
'Declare local variables.
Dim objDom
Dim objRoot
Dim objNode
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = false
objXML.load strXMLFile
Set objRoot = objXML.documentElement
Set objNode = objRoot.SelectSingleNode("contact[field/field_value='" & strEMail & "']")
objRoot.removeChild(objNode)
objXML.save strXMLFile
loadXMLFile strXMLFile,strXSLFile
End Function
Function addDetail(strXMLFile, strXSLFile, strEMail)
'Declare local variables.
Dim objDom
Dim objRoot
Dim objNode
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = false
objXML.load strXMLFile
Set objRoot = objXML.documentElement
Set objNode = objRoot.SelectSingleNode("contact[field/field_value='" & strEMail & "']")
objRoot.addChild(objNode)
objXML.save strXMLFile
loadXMLFile strXMLFile,strXSLFile
End Function
'-------------------------------------------------------------------
'This function accepts three paramters:
'strXMLFile - The XML file that you wish to view
'strXSLFile - The XSL stylesheet that will transform the XML file
'strEMail - The E-Mail address of the contact that you wish to view
'-------------------------------------------------------------------
Function updateDetail(strXMLFile, strXSLFile, strEMail)
Dim objDom
Dim objRoot
Dim objContact
Dim objField
Dim strNewEMail
strNewEMail = Request.Form("email")
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = false
objXML.load strXMLFile
Set objRoot = objXML.documentElement
Set objContact = objRoot.SelectSingleNode("contact[field/field_value='" & strEMail & "']")
For each objItem in Request.Form
Set objField = objContact.selectSingleNode("field[@id='" & objItem & "']/field_value")
objField.text = Request.Form(objItem)
Next
objXML.save strXMLFile
viewDetail strXMLFile, strXSLFile, strNewEMail
End Function
'-------------------------------------------------------------------
'This function accepts three paramters:
'strXMLFile - The XML file that you wish to view
'strXSLFile - The XSL stylesheet that will transform the XML file
'strEMail - The E-Mail address of the contact that you wish to view
'-------------------------------------------------------------------
Function viewDetail(strXMLFile, strXSLFile, strEMail)
Dim objXML
Dim objNode
Dim objXSL
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = false
objXML.load(strXMLFile)
Set objNode = objXML.SelectSingleNode("rolodex/contact[field/field_value='" & strEMail & "']")
set objXSL = Server.CreateObject("Microsoft.XMLDOM")
objXSL.async = false
objXSL.load(strXSLFile)
Response.Write(objNode.transformNode(objXSL))
End Function
'-------------------------------------------------------------------
'This function accepts two paramters:
'strXMLFile - The XML file that you wish to view
'strXSLFile - The XSL stylesheet that will transform the XML file
'-------------------------------------------------------------------
Function loadXMLFile(strXMLFile, strXSLFile)
Dim objXML
Dim objXSL
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = false
objXML.load(strXMLFile)
set objXSL = Server.CreateObject("Microsoft.XMLDOM")
objXSL.async = false
objXSL.load(strXSLFile)
Response.Write(objXML.transformNode(objXSL))
End Function
Dim strMode
Dim strEMail
strMode = Request.QueryString("mode")
strEMail = Request.QueryString("email")
Select Case strMode
Case "viewdetail"
viewDetail server.MapPath("rolodex6.xml"), server.MapPath("viewdetail.xsl"), strEMail
Case "editdetail"
viewDetail server.MapPath("rolodex6.xml"), server.MapPath("editdetail.xsl"), strEMail
Case "updatedetail"
updateDetail server.MapPath("rolodex6.xml"), server.MapPath("viewdetail.xsl"), strEMail
Case "deletedetail"
deleteDetail server.MapPath("rolodex6.xml"), server.MapPath("rolodex6.xsl"), strEMail
Case "addDetail"
addDetail server.MapPath("rolodex6.xml"), server.MapPath("rolodex6.xsl"), strEMail
Case Else
loadXMLFile server.MapPath("rolodex6.xml"), server.MapPath("rolodex6.xsl")
End Select
%>