vb 读 xml

xml 格式

<?xml version="1.0" encoding="gb2312"?>
<station_ip>
<ip_info address="123.62.28.32" port="80"/>
<ip_info address="211.139.10.174" port="80"/>
<ip_info address="202.171.253.99" port="80"/>
</station_ip>

 

代码


Dim XMLDoc As DOMDocument
Dim root As IXMLDOMNode

Dim xlst As IXMLDOMNodeList, xlst1 As IXMLDOMNodeList
Dim xn As IXMLDOMNode
Dim xnf As IXMLDOMNode
Dim xe As IXMLDOMElement

Private Sub Form_Load()

Call Load_Xml

End Sub

Private Sub Load_Xml()

Dim i As Integer
Dim j As Integer

Set XMLDoc = New DOMDocument
XMLDoc.Load ("C:\XmlForStation\ip.xml")
Set xn = XMLDoc.selectSingleNode("station_ip")

Dim xlstLength As Integer
Set xlst = xn.childNodes
xlstLength = xlst.length

ReDim aa(xlstLength, 2) As String

For i = 0 To xlst.length - 1 Step 1

For j = 0 To xlst.Item(i).Attributes.length - 1 Step 1
Debug.Print xlst.Item(i).Attributes.Item(j).nodeValue
aa(i, j) = xlst.Item(i).Attributes.Item(j).nodeValue

Next j

Next i


For i = 0 To UBound(aa, 1) - 1 Step 1

For j = 0 To UBound(aa, 2) - 1 Step 1
Debug.Print aa(i, j)

Next j

Next i


End Sub


Next i

End Sub

posted @ 2011-11-08 16:04  镇水古月  阅读(326)  评论(0编辑  收藏  举报