Public Shared Function testxmldocument()
Dim xmlstring As String = "<xxx><aa><bb>2222</bb><cc>3333</cc></aa></xxx>"
Dim doc As XmlDocument = New XmlDocument
doc.LoadXml(xmlstring) ' 加载xmlstring字符串到XmlDocument对象(如果字符串的格式不正确加载会报错)
Dim aanode As XmlNode = doc.SelectSingleNode("//xxx") '找到<xxx></xxx>节点之间的所有节点 XmlNode类型
Dim aanodelist As XmlNodeList = aanode.ChildNodes '获得<aa></aa>节点下的所有子节点 XmlNodeList类型
Dim node As XmlNode '定义节点XmlNode
For Each node In aanodelist '遍历XmlNodeList
Dim bb As String = node.Item("bb").FirstChild.InnerText.Trim() '找对应节点名字的值 <bb>2222</bb>
Dim cc As String = node.Item("cc").FirstChild.InnerText.Trim()
MessageBox.Show("bb:" + bb + "cc:" + cc)
Next
End Function
原文链接:https://www.f2er.com/vb/259040.html