专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VB Dotnet

Visual basic 2005怎么读取,查询xml文档

发布时间:2011-06-23 15:55:43 文章来源:www.iduyao.cn 采编人员:星星草
Visual basic 2005如何读取,查询xml文档?
xml文档内容如下:
<?xml   version= "1.0 "   encoding= "GB2312 "   standalone= "yes "?>
<AreaCodeConf>
<state   Name= '北京 '>
<City   Name= '北京 '   AreaCode= '1000 '>
<Branch   Name= '新世界 '   DispatchNo= '205 '/>
<Branch   Name= '左安门 '   DispatchNo= '206 '/>
</City>
</state>
<state   Name= '广东省 '>
<City   Name= '东莞 '   AreaCode= '1001 '>
<Branch   Name= '凤岗办事处 '   DispatchNo= '207 '/>
<Branch   Name= '常平办事处 '   DispatchNo= '208 '/>
</City>
<City   Name= '广州 '   AreaCode= '1002 '>
<Branch   Name= '海珠办事处 '   DispatchNo= '209 '/>
<Branch   Name= '东山办事处 '   DispatchNo= '210 '/>
</City>
</state>
</AreaCodeConf>

现在想读取此文档并由DispatchNo的值比如说是209知道是广东省广州海珠办事处,怎么写程序?

------解决方案--------------------
' 把xml存为d盘根目录的a.xml
' 程序不健壮,还需要完善

Imports System.Xml

Public Class Form1

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xd As New XmlDocument
xd.Load( "D:\a.xml ")
Dim nodes As XmlNodeList = xd.GetElementsByTagName( "Branch ")
Dim node As XmlNode
For i As Int32 = 0 To nodes.Count - 1
If nodes.ItemOf(i).Attributes.ItemOf(1).Value = TextBox1.Text Then
node = nodes.ItemOf(i)
End If
Next
Dim strBrach As String = node.Attributes.ItemOf(0).Value.ToString
Dim strCity As String = node.ParentNode.Attributes.ItemOf(0).Value.ToString & " "
Dim strProvince As String = node.ParentNode.ParentNode.Attributes.ItemOf(0).Value.ToString & " "
Dim s As String = strProvince & strCity & strBrach
MsgBox(s)
End Sub
End Class
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: