用asp文件更新xml文件的asp源码 要求详细代码! 最简单明白的!谢谢!
展开全部
下面的希望是你需要的,能给你帮助:
编写Userdata.asp程序来完成XML文件转换,数据的浏览、修改、删除:
<%
''-------------------------------------------------------------------
''删除记录函数deleteDetail
''strXMLFile - 要载入的XML文件。
''strXSLFile - 显示XML文件的XSL样式单文件。
''strEMail - 要删除客户的电子邮件。
''-------------------------------------------------------------------
Function deleteDetail(strXMLFile, strXSLFile, strEMail)
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("个人资料[field/field_value=''" & strEMail & "'']")
objRoot.removeChild(objNode)
objXML.save strXMLFile
loadXMLFile strXMLFile,strXSLFile
End Function
''-------------------------------------------------------------------
''更新记录函数updateDetail
''-------------------------------------------------------------------
Function updateDetail(strXMLFile, strXSLFile, strEMail)
''Declare local variables.
Dim objDom
Dim objRoot
Dim objContact
Dim objField
Dim strNewEMail
strNewEMail = Request.Form("电子邮件")
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = false
objXML.load strXMLFile
Set objRoot = objXML.documentElement
Set objContact = objRoot.SelectSingleNode("个人资料[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
''-------------------------------------------------------------------
''显示个人详细资料函数viewDetail
''-------------------------------------------------------------------
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("客户资料表/个人资料[field/field_value=''" & strEMail & "'']")
set objXSL = Server.CreateObject("Microsoft.XMLDOM")
objXSL.async = false
objXSL.load(strXSLFile)
Response.Write(objNode.transformNode(objXSL))
End Function
''-------------------------------------------------------------------
''显示所有信息函数loadXMLFile
''-------------------------------------------------------------------
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("Userdata.xml"), server.MapPath("viewdetail.xsl"), strEMail
Case "editdetail"
viewDetail server.MapPath("Userdata.xml"), server.MapPath("editdetail.xsl"), strEMail
Case "updatedetail"
updateDetail server.MapPath("Userdata.xml"), server.MapPath("viewdetail.xsl"), strEMail
Case "deletedetail"
deleteDetail server.MapPath("Userdata.xml"), server.MapPath("Userdata.xsl"), strEMail
Case Else
loadXMLFile server.MapPath("Userdata.xml"), server.MapPath("Userdata.xsl")
End Select
%>
我们可以利用下面的文件来完成新客户信息的输入,文件addnewdata.htm如下:
<html><head><title>客户信息输入</title></head>
<body bgcolor="#0099ff">
<form action="processAdd.asp" method="post">
<h3>请输入您的客户信息</h3>
姓 名: <input type="text" id="姓名" name="姓名"><br>
性 别: <input type="text" id="性别" name="性别"><br>
地 址: <input type="text" id="地址" name="地址"><br>
邮政编码: <input type="text" id="邮政编码" name="邮政编码"><br>
电 话: <input type="text" id="电话" name="电话"><br>
电子邮件: <input type="text" id="电子邮件" name="电子邮件"><br><br>
<input type="submit" id="btnSub" name="btnSub" value="填好了,发送"><br>
</form>
</body>
</html>
当填写完上面的表单后,提交到数据处理程序processAdd.asp,本程序可以判断Userdata.xml文件是否存在,如果不存在,就建立新文件;否则把提交的数据添加到Userdata.xml中。然后根据提交成功与否,显示数据保存成功与失败。processAdd.asp程序如下:
<%
''--------------------------------------------------------------------
''添加数据的函数addNewdatatoXML
''--------------------------------------------------------------------
Function addNewdatatoXML(strFileName)
Dim objDom
Dim objRoot
Dim objRecord
Dim objField
Dim objFieldValue
Dim objattID
Dim objattTabOrder
Dim objPI
Dim blnFileExists
Dim x
Set objDom = server.CreateObject("Microsoft.XMLDOM")
objDom.preserveWhiteSpace = True
blnFileExists = objDom.Load(strFileName)
If blnFileExists = True Then
Set objRoot = objDom.documentElement
Else
Set objRoot = objDom.createElement("客户资料表")
objDom.appendChild objRoot
End If
Set objRecord = objDom.createElement("个人资料")
objRoot.appendChild objRecord
For x = 1 To Request.Form.Count
If instr(1,Request.Form.Key(x),"btn") = 0 Then
Set objField = objDom.createElement("field")
Set objattID = objDom.createAttribute("id")
objattID.Text = Request.Form.Key(x)
objField.setAttributeNode objattID
Set objattTabOrder = objDom.createAttribute("taborder")
objattTabOrder.Text = x
objField.setAttributeNode objattTabOrder
Set objFieldValue = objDom.createElement("field_value")
objFieldValue.Text = Request.Form(x)
objRecord.appendChild objField
objField.appendChild objFieldValue
End If
Next
If blnFileExists = False then
Set objPI = objDom.createProcessingInstruction("xml", "version=''1.0'' encoding=''gb2312''")
objDom.insertBefore objPI, objDom.childNodes(0)
End If
objDom.save strFileName
Set objDom = Nothing
Set objRoot = Nothing
Set objRecord = Nothing
Set objField = Nothing
Set objFieldValue = Nothing
Set objattID = Nothing
Set objattTabOrder = Nothing
Set objPI = Nothing
End Function
On Error Resume Next
addNewdatatoXML server.MapPath("Userdata.xml")
If err.number <> 0 then
Response.write("<html><body bgcolor=''#0099ff''><center><font color=red><b>您提交的表单没有成功保存,请重新提交!!</b><br><br><a href=''javascript:history.go(-1)''>点击这里重新进行提交。</a></body></html>")
Else
Response.write("<html><body bgcolor=''#0099ff''><center><font color=red><b>您提交的表单已经成功保存!!!</b><br><br><a href=''Userdata.asp''>点击这里查看添加后客户资料?lt;/a></body></html>")
End If
%>
至此,我们完成对XML文件进行数据添加、浏览、修改、删除的所有工作。以上程序在iis+IE6和Netscape下调试通过。
祝福你,朋友!
编写Userdata.asp程序来完成XML文件转换,数据的浏览、修改、删除:
<%
''-------------------------------------------------------------------
''删除记录函数deleteDetail
''strXMLFile - 要载入的XML文件。
''strXSLFile - 显示XML文件的XSL样式单文件。
''strEMail - 要删除客户的电子邮件。
''-------------------------------------------------------------------
Function deleteDetail(strXMLFile, strXSLFile, strEMail)
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("个人资料[field/field_value=''" & strEMail & "'']")
objRoot.removeChild(objNode)
objXML.save strXMLFile
loadXMLFile strXMLFile,strXSLFile
End Function
''-------------------------------------------------------------------
''更新记录函数updateDetail
''-------------------------------------------------------------------
Function updateDetail(strXMLFile, strXSLFile, strEMail)
''Declare local variables.
Dim objDom
Dim objRoot
Dim objContact
Dim objField
Dim strNewEMail
strNewEMail = Request.Form("电子邮件")
set objXML = Server.CreateObject("Microsoft.XMLDOM")
objXML.async = false
objXML.load strXMLFile
Set objRoot = objXML.documentElement
Set objContact = objRoot.SelectSingleNode("个人资料[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
''-------------------------------------------------------------------
''显示个人详细资料函数viewDetail
''-------------------------------------------------------------------
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("客户资料表/个人资料[field/field_value=''" & strEMail & "'']")
set objXSL = Server.CreateObject("Microsoft.XMLDOM")
objXSL.async = false
objXSL.load(strXSLFile)
Response.Write(objNode.transformNode(objXSL))
End Function
''-------------------------------------------------------------------
''显示所有信息函数loadXMLFile
''-------------------------------------------------------------------
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("Userdata.xml"), server.MapPath("viewdetail.xsl"), strEMail
Case "editdetail"
viewDetail server.MapPath("Userdata.xml"), server.MapPath("editdetail.xsl"), strEMail
Case "updatedetail"
updateDetail server.MapPath("Userdata.xml"), server.MapPath("viewdetail.xsl"), strEMail
Case "deletedetail"
deleteDetail server.MapPath("Userdata.xml"), server.MapPath("Userdata.xsl"), strEMail
Case Else
loadXMLFile server.MapPath("Userdata.xml"), server.MapPath("Userdata.xsl")
End Select
%>
我们可以利用下面的文件来完成新客户信息的输入,文件addnewdata.htm如下:
<html><head><title>客户信息输入</title></head>
<body bgcolor="#0099ff">
<form action="processAdd.asp" method="post">
<h3>请输入您的客户信息</h3>
姓 名: <input type="text" id="姓名" name="姓名"><br>
性 别: <input type="text" id="性别" name="性别"><br>
地 址: <input type="text" id="地址" name="地址"><br>
邮政编码: <input type="text" id="邮政编码" name="邮政编码"><br>
电 话: <input type="text" id="电话" name="电话"><br>
电子邮件: <input type="text" id="电子邮件" name="电子邮件"><br><br>
<input type="submit" id="btnSub" name="btnSub" value="填好了,发送"><br>
</form>
</body>
</html>
当填写完上面的表单后,提交到数据处理程序processAdd.asp,本程序可以判断Userdata.xml文件是否存在,如果不存在,就建立新文件;否则把提交的数据添加到Userdata.xml中。然后根据提交成功与否,显示数据保存成功与失败。processAdd.asp程序如下:
<%
''--------------------------------------------------------------------
''添加数据的函数addNewdatatoXML
''--------------------------------------------------------------------
Function addNewdatatoXML(strFileName)
Dim objDom
Dim objRoot
Dim objRecord
Dim objField
Dim objFieldValue
Dim objattID
Dim objattTabOrder
Dim objPI
Dim blnFileExists
Dim x
Set objDom = server.CreateObject("Microsoft.XMLDOM")
objDom.preserveWhiteSpace = True
blnFileExists = objDom.Load(strFileName)
If blnFileExists = True Then
Set objRoot = objDom.documentElement
Else
Set objRoot = objDom.createElement("客户资料表")
objDom.appendChild objRoot
End If
Set objRecord = objDom.createElement("个人资料")
objRoot.appendChild objRecord
For x = 1 To Request.Form.Count
If instr(1,Request.Form.Key(x),"btn") = 0 Then
Set objField = objDom.createElement("field")
Set objattID = objDom.createAttribute("id")
objattID.Text = Request.Form.Key(x)
objField.setAttributeNode objattID
Set objattTabOrder = objDom.createAttribute("taborder")
objattTabOrder.Text = x
objField.setAttributeNode objattTabOrder
Set objFieldValue = objDom.createElement("field_value")
objFieldValue.Text = Request.Form(x)
objRecord.appendChild objField
objField.appendChild objFieldValue
End If
Next
If blnFileExists = False then
Set objPI = objDom.createProcessingInstruction("xml", "version=''1.0'' encoding=''gb2312''")
objDom.insertBefore objPI, objDom.childNodes(0)
End If
objDom.save strFileName
Set objDom = Nothing
Set objRoot = Nothing
Set objRecord = Nothing
Set objField = Nothing
Set objFieldValue = Nothing
Set objattID = Nothing
Set objattTabOrder = Nothing
Set objPI = Nothing
End Function
On Error Resume Next
addNewdatatoXML server.MapPath("Userdata.xml")
If err.number <> 0 then
Response.write("<html><body bgcolor=''#0099ff''><center><font color=red><b>您提交的表单没有成功保存,请重新提交!!</b><br><br><a href=''javascript:history.go(-1)''>点击这里重新进行提交。</a></body></html>")
Else
Response.write("<html><body bgcolor=''#0099ff''><center><font color=red><b>您提交的表单已经成功保存!!!</b><br><br><a href=''Userdata.asp''>点击这里查看添加后客户资料?lt;/a></body></html>")
End If
%>
至此,我们完成对XML文件进行数据添加、浏览、修改、删除的所有工作。以上程序在iis+IE6和Netscape下调试通过。
祝福你,朋友!
追问
我要显示的xml文件内容
000|01|02|03|04|05|06|07|08|09|10|11|
addnewdata.htm下:保存后让xml显示以上内容的
这样帮我弄个源码,谢谢!可以吗?
展开全部
<%
dim fso,ts
setfso =server.createobject("scripting.filesystemobject")//创建一个服务器羰
set ts=fso.opentextfile(server.mappath("vip.xml"),2,true)
quot=chr(34)'chr(34)表示双引号
t= chr(9)'chr(9)表示一个TabTabTabTab
ts.writeline("<?xml version="" &"1.0" " &"encoding="& quot &"gb2312" " &?>")
ts.writeline("<books>")
ts.writeline(t& "<book>")
ts.writeline(t&t&"<isbn>110-110-110</isbn>")
ts.writeline(t&t&"<author>李小毛</author>")
ts.writeline(t&t&"<description>这是一本非常好的书!</description>")
ts.writeline(t& "</book>")
ts.writeline("</books>")
ts.closet
set ts=nothing
set fso =nothing
%>
这是一个简单的asp生成XML文件的例子,你可参照做一下试试
dim fso,ts
setfso =server.createobject("scripting.filesystemobject")//创建一个服务器羰
set ts=fso.opentextfile(server.mappath("vip.xml"),2,true)
quot=chr(34)'chr(34)表示双引号
t= chr(9)'chr(9)表示一个TabTabTabTab
ts.writeline("<?xml version="" &"1.0" " &"encoding="& quot &"gb2312" " &?>")
ts.writeline("<books>")
ts.writeline(t& "<book>")
ts.writeline(t&t&"<isbn>110-110-110</isbn>")
ts.writeline(t&t&"<author>李小毛</author>")
ts.writeline(t&t&"<description>这是一本非常好的书!</description>")
ts.writeline(t& "</book>")
ts.writeline("</books>")
ts.closet
set ts=nothing
set fso =nothing
%>
这是一个简单的asp生成XML文件的例子,你可参照做一下试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼上回答已经很详细了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询