dabears60090
10-19-2007, 02:05 PM
hi. asp & xml newbie here. can someone please help me? i created the asp code below to append into an existing xml file but i'm getting an error.
<html>
<body>
<%
'--------------------------------------------------------------------
'The "addNewContacttoXML" Function accepts one parameters.
'strXMLFile - The physical path and the XML file will be saved.
'--------------------------------------------------------------------
Function addNewContacttoXML(strXmlFile)
'Declare local variables.
Dim xmlDoc
Dim xmlRoot
Dim xmlProject
Dim xmlPrjSt
Dim xmlPrjNum
Dim xmlPrjNme
Dim xmlPrjEfDt
Dim xmlPrjPhs
Dim xmlPrjPMP
Dim xmlPrjAllCnt
Dim xmlPrjAlsCnt
Dim xmlPrjAlsLib1
Dim xmlPrjAlsLib2
Dim xmlPrjAlsLib3
Dim xmlPrjAllUrlD
Dim xmlPrjAllUrlQ
Dim xmlPrjAllUrlLT
Dim addPrjNum
'Instantiate the Microsoft XMLDOM.
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async = false
'xmlDoc.preserveWhiteSpace = True
'Call the Load Method of the XMLDOM Object. The Load Method has a
'boolean return value indicating whether or not the file could be
'loaded. If the file exists and loads it will return true, otherwise,
'it will return false.
xmlDoc.Load (strXmlFile)
'If the file loaded set the objRoot Object equal to the root element
'of the XML document.
Set xmlRoot = xmlDoc.documentElement
'Create the new container element for the new record.
Set xmlProject = xmlDoc.createElement("project")
xmlRoot.appendChild xmlProject
Set xmlPrjSt = xmlDoc.createElement("prjst")
Set xmlPrjNum = xmlDoc.createElement("prjnum")
Set xmlPrjNme = xmlDoc.createElement("prjnme")
Set xmlPrjEfDt = xmlDoc.createElement("prjefdt")
Set xmlPrjPhs = xmlDoc.createElement("prjphs")
Set xmlPrjPMP = xmlDoc.createElement("prjpmp")
Set xmlPrjAllCnt = xmlDoc.createElement("prjallcnt")
Set xmlPrjAlsCnt = xmlDoc.createElement("prjalscnt")
Set xmlPrjAlsLib1 = xmlDoc.createElement("prjalslib1")
Set xmlPrjAlsLib2 = xmlDoc.createElement("prjalslib2")
Set xmlPrjAlsLib3 = xmlDoc.createElement("prjalslib3")
Set xmlPrjAllUrlD = xmlDoc.createElement("prjallurld")
Set xmlPrjAllUrlQ = xmlDoc.createElement("prjallurlq")
Set xmlPrjAllUrlLT = xmlDoc.createElement("prjallurllt")
xmlPrjSt.Text = Request.Form("prjState")
xmlPrjNum.Text = Request.Form("prjNum")
addPrjNum = Request.Form("prjNum")
xmlPrjNme.Text = Request.Form("prjNme")
Dim frmPrjEfDt
frmPrjEfDt = Request.Form("prjEfDt")
If frmPrjEfDt <>"" Then
xmlPrjEfDt.Text = frmPrjEfDt
Else
xmlPrjEfDt.Text = " "
End If
Dim frmPrjPhs
frmPrjPhs = Request.Form("prjPhs")
If frmPrjPhs <>"" Then
xmlPrjPhs.Text = frmPrjPhs
Else
xmlPrjPhs.Text = " "
End If
Dim frmPrjPMP
frmPrjPMP = Request.Form("prjPMP")
If frmPrjPMP <>"" Then
xmlPrjPMP.Text = frmPrjPMP
Else
xmlPrjPMP.Text = " "
End If
Dim frmPrjAllCnt
frmPrjAllCnt = Request.Form("prjAllCont")
If frmPrjAllCnt <>"" Then
xmlPrjAllCnt.Text = frmPrjAllCnt
Else
xmlPrjAllCnt.Text = " "
End If
Dim frmPrjAlsCnt
frmPrjAlsCnt = Request.Form("prjAlsCont")
If frmPrjAlsCnt <>"" Then
xmlPrjAlsCnt.Text = frmPrjAlsCnt
Else
xmlPrjAlsCnt.Text = " "
End If
Dim frmPrjAlslibs
frmPrjAlslibs = Request.Form("prjAlsLibs")
frmPrjAlsLibs = frmPrjAlsLibs.split("\n")
If frmPrjAlsLibs(0) <>"" Then
xmlPrjAlsLib1.Text = frmPrjAlsLibs(0)
Else
xmlPrjAlsLib1.Text = " "
End If
If frmPrjAlsLibs(1) <>"" Then
xmlPrjAlsLib2.Text = frmPrjAlsLibs(1)
Else
xmlPrjAlsLib2.Text = " "
End If
If frmPrjAlsLibs(2) <>"" Then
xmlPrjAlsLib3.Text = frmPrjAlsLibs(2)
Else
xmlPrjAlsLib3.Text = " "
End If
Dim frmPrjAllUrlD
frmPrjAllUrlD = Request.Form("prjAllUrlD")
If frmPrjAllUrlD <>"" Then
xmlPrjAllUrlD.Text = frmPrjAllUrlD
Else
xmlPrjAllUrlD.Text = " "
End If
Dim frmPrjAllUrlQ
frmPrjAllUrlQ = Request.Form("prjAllUrlQ")
If frmPrjAllUrlQ <>"" Then
xmlPrjAllUrlQ.Text = frmPrjAllUrlQ
Else
xmlPrjAllUrlQ.Text = " "
End If
Dim frmPrjAllUrlLT
frmPrjAllUrlLT = Request.Form("prjAllUrlLT")
If frmPrjAllUrlLT <>"" Then
xmlPrjAllUrlLT.Text = frmPrjAllUrlLT
Else
xmlPrjAllUrlLT.Text = " "
End If
xmlProject.appendChild xmlPrjSt
xmlProject.appendChild xmlPrjNum
xmlProject.appendChild xmlPrjNme
xmlProject.appendChild xmlPrjEfDt
xmlProject.appendChild xmlPrjPhs
xmlProject.appendChild xmlPrjPMP
xmlProject.appendChild xmlPrjAllCnt
xmlProject.appendChild xmlPrjAlsCnt
xmlProject.appendChild xmlPrjAlsLib1
xmlProject.appendChild xmlPrjAlsLib2
xmlProject.appendChild xmlPrjAlsLib3
xmlProject.appendChild xmlPrjAllUrlD
xmlProject.appendChild xmlPrjAllUrlQ
xmlProject.appendChild xmlPrjAllUrlLT
'Save the XML document.
xmlDoc.save strXmlFile
'Release all of your object references.
Set xmlDoc = Nothing
Set xmlRoot = Nothing
Set xmlProject = Nothing
Set xmlPrjSt = Nothing
Set xmlPrjNum = Nothing
Set xmlPrjNme = Nothing
Set xmlPrjEfDt = Nothing
Set xmlPrjPhs = Nothing
Set xmlPrjPMP = Nothing
Set xmlPrjAllCnt = Nothing
Set xmlPrjAlsCnt = Nothing
Set xmlPrjAlsLib1 = Nothing
Set xmlPrjAlsLib2 = Nothing
Set xmlPrjAlsLib3 = Nothing
Set xmlPrjAllUrlD = Nothing
Set xmlPrjAllUrlQ = Nothing
Set xmlPrjAllUrlLT = Nothing
End Function
'Do not break on an error.
On Error Resume Next
'Call the addNewContacttoXML function, passing in the physical path to
'save the file to and the name that you wish to use for the file.
Dim xmlFile
xmlFile = "ProjList.xml"
addNewContacttoXML xmlFile
'Test to see if an error occurred, if so, let the user know.
'Otherwise, tell the user that the operation was successful.
If err.number <> 0 then
%>
<script language="javascript">
<!--
window.alert("Error adding Project");
// window.history.go(-2);
//-->
</script>
<%
Response.Write("Err No: " + err.number)
Else
%>
<script language="javascript">
<!--
window.alert("Project successfully added!");
window.history.go(-2);
//-->
</script>
<%
End If
%>
</body>
</html>
appreciate any help.
thanks.
<html>
<body>
<%
'--------------------------------------------------------------------
'The "addNewContacttoXML" Function accepts one parameters.
'strXMLFile - The physical path and the XML file will be saved.
'--------------------------------------------------------------------
Function addNewContacttoXML(strXmlFile)
'Declare local variables.
Dim xmlDoc
Dim xmlRoot
Dim xmlProject
Dim xmlPrjSt
Dim xmlPrjNum
Dim xmlPrjNme
Dim xmlPrjEfDt
Dim xmlPrjPhs
Dim xmlPrjPMP
Dim xmlPrjAllCnt
Dim xmlPrjAlsCnt
Dim xmlPrjAlsLib1
Dim xmlPrjAlsLib2
Dim xmlPrjAlsLib3
Dim xmlPrjAllUrlD
Dim xmlPrjAllUrlQ
Dim xmlPrjAllUrlLT
Dim addPrjNum
'Instantiate the Microsoft XMLDOM.
Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
xmlDoc.async = false
'xmlDoc.preserveWhiteSpace = True
'Call the Load Method of the XMLDOM Object. The Load Method has a
'boolean return value indicating whether or not the file could be
'loaded. If the file exists and loads it will return true, otherwise,
'it will return false.
xmlDoc.Load (strXmlFile)
'If the file loaded set the objRoot Object equal to the root element
'of the XML document.
Set xmlRoot = xmlDoc.documentElement
'Create the new container element for the new record.
Set xmlProject = xmlDoc.createElement("project")
xmlRoot.appendChild xmlProject
Set xmlPrjSt = xmlDoc.createElement("prjst")
Set xmlPrjNum = xmlDoc.createElement("prjnum")
Set xmlPrjNme = xmlDoc.createElement("prjnme")
Set xmlPrjEfDt = xmlDoc.createElement("prjefdt")
Set xmlPrjPhs = xmlDoc.createElement("prjphs")
Set xmlPrjPMP = xmlDoc.createElement("prjpmp")
Set xmlPrjAllCnt = xmlDoc.createElement("prjallcnt")
Set xmlPrjAlsCnt = xmlDoc.createElement("prjalscnt")
Set xmlPrjAlsLib1 = xmlDoc.createElement("prjalslib1")
Set xmlPrjAlsLib2 = xmlDoc.createElement("prjalslib2")
Set xmlPrjAlsLib3 = xmlDoc.createElement("prjalslib3")
Set xmlPrjAllUrlD = xmlDoc.createElement("prjallurld")
Set xmlPrjAllUrlQ = xmlDoc.createElement("prjallurlq")
Set xmlPrjAllUrlLT = xmlDoc.createElement("prjallurllt")
xmlPrjSt.Text = Request.Form("prjState")
xmlPrjNum.Text = Request.Form("prjNum")
addPrjNum = Request.Form("prjNum")
xmlPrjNme.Text = Request.Form("prjNme")
Dim frmPrjEfDt
frmPrjEfDt = Request.Form("prjEfDt")
If frmPrjEfDt <>"" Then
xmlPrjEfDt.Text = frmPrjEfDt
Else
xmlPrjEfDt.Text = " "
End If
Dim frmPrjPhs
frmPrjPhs = Request.Form("prjPhs")
If frmPrjPhs <>"" Then
xmlPrjPhs.Text = frmPrjPhs
Else
xmlPrjPhs.Text = " "
End If
Dim frmPrjPMP
frmPrjPMP = Request.Form("prjPMP")
If frmPrjPMP <>"" Then
xmlPrjPMP.Text = frmPrjPMP
Else
xmlPrjPMP.Text = " "
End If
Dim frmPrjAllCnt
frmPrjAllCnt = Request.Form("prjAllCont")
If frmPrjAllCnt <>"" Then
xmlPrjAllCnt.Text = frmPrjAllCnt
Else
xmlPrjAllCnt.Text = " "
End If
Dim frmPrjAlsCnt
frmPrjAlsCnt = Request.Form("prjAlsCont")
If frmPrjAlsCnt <>"" Then
xmlPrjAlsCnt.Text = frmPrjAlsCnt
Else
xmlPrjAlsCnt.Text = " "
End If
Dim frmPrjAlslibs
frmPrjAlslibs = Request.Form("prjAlsLibs")
frmPrjAlsLibs = frmPrjAlsLibs.split("\n")
If frmPrjAlsLibs(0) <>"" Then
xmlPrjAlsLib1.Text = frmPrjAlsLibs(0)
Else
xmlPrjAlsLib1.Text = " "
End If
If frmPrjAlsLibs(1) <>"" Then
xmlPrjAlsLib2.Text = frmPrjAlsLibs(1)
Else
xmlPrjAlsLib2.Text = " "
End If
If frmPrjAlsLibs(2) <>"" Then
xmlPrjAlsLib3.Text = frmPrjAlsLibs(2)
Else
xmlPrjAlsLib3.Text = " "
End If
Dim frmPrjAllUrlD
frmPrjAllUrlD = Request.Form("prjAllUrlD")
If frmPrjAllUrlD <>"" Then
xmlPrjAllUrlD.Text = frmPrjAllUrlD
Else
xmlPrjAllUrlD.Text = " "
End If
Dim frmPrjAllUrlQ
frmPrjAllUrlQ = Request.Form("prjAllUrlQ")
If frmPrjAllUrlQ <>"" Then
xmlPrjAllUrlQ.Text = frmPrjAllUrlQ
Else
xmlPrjAllUrlQ.Text = " "
End If
Dim frmPrjAllUrlLT
frmPrjAllUrlLT = Request.Form("prjAllUrlLT")
If frmPrjAllUrlLT <>"" Then
xmlPrjAllUrlLT.Text = frmPrjAllUrlLT
Else
xmlPrjAllUrlLT.Text = " "
End If
xmlProject.appendChild xmlPrjSt
xmlProject.appendChild xmlPrjNum
xmlProject.appendChild xmlPrjNme
xmlProject.appendChild xmlPrjEfDt
xmlProject.appendChild xmlPrjPhs
xmlProject.appendChild xmlPrjPMP
xmlProject.appendChild xmlPrjAllCnt
xmlProject.appendChild xmlPrjAlsCnt
xmlProject.appendChild xmlPrjAlsLib1
xmlProject.appendChild xmlPrjAlsLib2
xmlProject.appendChild xmlPrjAlsLib3
xmlProject.appendChild xmlPrjAllUrlD
xmlProject.appendChild xmlPrjAllUrlQ
xmlProject.appendChild xmlPrjAllUrlLT
'Save the XML document.
xmlDoc.save strXmlFile
'Release all of your object references.
Set xmlDoc = Nothing
Set xmlRoot = Nothing
Set xmlProject = Nothing
Set xmlPrjSt = Nothing
Set xmlPrjNum = Nothing
Set xmlPrjNme = Nothing
Set xmlPrjEfDt = Nothing
Set xmlPrjPhs = Nothing
Set xmlPrjPMP = Nothing
Set xmlPrjAllCnt = Nothing
Set xmlPrjAlsCnt = Nothing
Set xmlPrjAlsLib1 = Nothing
Set xmlPrjAlsLib2 = Nothing
Set xmlPrjAlsLib3 = Nothing
Set xmlPrjAllUrlD = Nothing
Set xmlPrjAllUrlQ = Nothing
Set xmlPrjAllUrlLT = Nothing
End Function
'Do not break on an error.
On Error Resume Next
'Call the addNewContacttoXML function, passing in the physical path to
'save the file to and the name that you wish to use for the file.
Dim xmlFile
xmlFile = "ProjList.xml"
addNewContacttoXML xmlFile
'Test to see if an error occurred, if so, let the user know.
'Otherwise, tell the user that the operation was successful.
If err.number <> 0 then
%>
<script language="javascript">
<!--
window.alert("Error adding Project");
// window.history.go(-2);
//-->
</script>
<%
Response.Write("Err No: " + err.number)
Else
%>
<script language="javascript">
<!--
window.alert("Project successfully added!");
window.history.go(-2);
//-->
</script>
<%
End If
%>
</body>
</html>
appreciate any help.
thanks.