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")