PDA

View Full Version : how to declare a adddetail function ??


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
%>

glenngv
09-18-2002, 05:08 AM
change the line:

objRoot.addChild(objNode)

to:

objRoot.appendChild(objNode)


just a note, in vbscript, if your procedure returns nothing, you declare it like this:

Sub addDetail(strXMLFile, strXSLFile, strEMail)
'codes here

End Sub

then you call it like this:
addDetail "param1","param2","param3"
or:
Call addDetail("param1","param2","param3")


if you want to return something, use:

Function addDetail(strXMLFile, strXSLFile, strEMail)
'codes here

addDetail = blah
End Function

and you call it like this:
myvar = addDetail("param1","param2","param3")


in your case, since you are not returning something, you should use Sub instead of Function.

asad_ks
05-23-2005, 11:49 AM
Hi, earliar asp script shows update,edit delete functions of user input to the form..but theres no add function, as your suggesion i have added code for "add" record in XML file, and also i have added 1 extra line in viewdetail.xsl file and calling addDetail Proccedure, but after clicking at the "Add new record link" threre is reflection in page and it shows the view record page, please guide me with all ASP,XSL and XML file.
i am pasing ASP code below.

asad
--------------------------------------------------------------

<%
'-------------------------------------------------------------------
'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




Sub 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.appendChild(objNode)

objXML.save strXMLFile

loadXMLFile strXMLFile,strXSLFile
End Sub



'-------------------------------------------------------------------
'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
%>

glenngv
05-23-2005, 12:26 PM
Almost 3 yrs has passed and still has not solved it? :confused:
Are you and wanye the same person?
I have totally forgotten this thread.