当前位置: 网学 > 编程文档 > ASP > 正文

实例演练ASP+XML编程

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/17
下载{$ArticleTitle}原创论文样式
c)
 Dim objPerson, objNode

 ClearError

 If objXmlDoc Is Nothing Then
  AddToXml = False
  AddErr "Dom对象为空值"
  Exit Function
 End If

 '' 创建Person节点
 Set objPerson = objXmlDoc.createElement("Person")
 objXmlDoc.documentElement.appendChild objPerson

 '' 创建各个子节点
 ''-----------------------------------------------------
 Set objNode = objXmlDoc.createElement("Name")
 objNode.Text = m_strName
 objPerson.appendChild objNode

 Set objNode = objXmlDoc.createElement("Nick")
 objNode.Text = m_strNick
 objPerson.appendChild objNode

 Set objNode = objXmlDoc.createElement("Mobile")
 objNode.Text = m_strMobile
 objPerson.appendChild objNode

 Set objNode = objXmlDoc.createElement("Tel")
 objNode.Text = m_strTel
 objPerson.appendChild objNode

 Set objNode = objXmlDoc.createElement("Email")
 objNode.Text = m_strEmail
 objPerson.appendChild objNode

 Set objNode = objXmlDoc.createElement("QQ")
 objNode.Text = m_strQQ
 objPerson.appendChild objNode

 Set objNode = objXmlDoc.createElement("Company")
 objNode.Text = m_strCompany
 objPerson.appendChild objNode
 ''-----------------------------------------------------

 Set objNode = Nothing
 Set objPerson = Nothing

  On Error Resume Next
 objXmlDoc.save Server.MapPath(C_XMLFILE) ''保存XML文件
 If Err.Number = 0 Then
  AddToXml = True
 Else
  AddToXml = False
  AddErr Err.Description
 End If
End Function

'' 从XML文件中删除数据
'' 需要首先设置Id
Public Function DeleteFromXml(objXmlDoc)
 Dim objNodeList, objNode

 ClearError

 If objXmlDoc Is Nothing Then
  DeleteFromXml = False
  AddErr "Dom对象为空值"
  Exit Function
 End If

 If CStr(m_intId) = "-1" Then
  DeleteFromXml = False
  AddErr "未正确设置联系人对象的ID属性"
  Exit Function
 End If

 Set objNodeList = objXmlDoc.getElementsByTagName("Person")
 If objNodeList.length - m_intId < 0 Then
  DeleteFromXml = False
  AddErr "未找到相应的联系人"
  Set objNodeList = Nothing
  Exit Function
 End If

 On Error Resume Next
 Set objNode = objXmlDoc.documentElement.removeChild(objNodeList(intId-1))
 If objNode Is Nothing Then
  DeleteFromXml = False
  AddErr "删除联系人失败"
  Set objNodeList = Nothing
  Exit Function
 Else
  objXmlDoc.save Server.MapPath(C_XMLFILE)
 End If
 Set objNode = Nothing
 Set objNodeList = Nothing

 If Err.Number = 0 Then
  DeleteFromXml = True
 Else
  DeleteFromXml = False
  AddErr Err.Description
 End If
End Function

'' 修改XML文件中的数据
'' 需要首先设置好Id
Public Function EditToXml(objXmlDoc)
 Dim objPersonList, objOldPerson, objNewPerson, objNode

 ClearError

 If objXmlDoc Is Nothing Then
  EditToXml = False
  AddErr "Dom对象为空值"
  Exit Function
 End If

 If CStr(m_intId) = "-1" Then
  EditToXml = False
  AddErr "未正确设置联系人对象的ID属性"
  Exit Function
 End If

 Set objPersonList = objXmlDoc.getElementsByTagName("Person")

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号