实例演练ASP+XML编程比较全的了第1/2页(6)


End Function 

' 私有方法,添加错误信息 
Private Sub AddErr(strEcho) 
 m_strError = m_strError + "<Div CLASS=""alert"">" & strEcho & "</Div>" 
End Sub 

' 清除错误信息 
Public Function ClearError() 
 m_strError = "" 
End Function 

' 从Xml中读取指定节点的数据,并填充各个属性 
' 需要首先设置Id 
Public Function GetInfoFromXml(objXmlDoc) 
 Dim objNodeList 
 Dim I 

 ClearError 

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

 If CStr(m_intId) = "-1" Then 
  GetInfoFromXml = False 
  AddErr "未正确设置联系人对象的ID属性" 
  Exit Function 
 Else 
  I = m_intId - 1 ' 要读取得节点位置 
 End If 

 ' 选择并读取节点信息,赋予各个属性 
 Set objNodeList = objXmlDoc.getElementsByTagName("Person") 
 If objNodeList.length - m_intId >= 0 Then 
  On Error Resume Next 
  m_strName = objNodeList(I).selectSingleNode("Name").Text 
  m_strNick = objNodeList(I).selectSingleNode("Nick").Text 
  m_strMobile = objNodeList(I).selectSingleNode("Mobile").Text 
  m_strTel = objNodeList(I).selectSingleNode("Tel").Text 
  m_strEmail = objNodeList(I).selectSingleNode("Email").Text 
  m_strQQ = objNodeList(I).selectSingleNode("QQ").Text 
  m_strCompany = objNodeList(I).selectSingleNode("Company").Text 
  GetInfoFromXml = True 
 Else 
  GetInfoFromXml = False 
  AddErr "获取联系信息发生错误" 
  Set objNodeList = Nothing 
  Exit Function 
 End If 
 Set objNodeList = Nothing 
End Function 

' 添加信息到XML文件中 
' 需要首先设置好要填充的属性 
Public Function AddToXml(objXmlDoc) 
 Dim objPerson, objNode 

 ClearError 

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

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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/3097.html