用vb读取XMl文件的数据的问题,大家看我错那了!
发布网友
发布时间:2022-11-08 06:41
我来回答
共1个回答
热心网友
时间:2023-11-08 01:06
嗯嗯,大致上要按照树的关系去找节点,读之
比如xml是
<root>
<design>
<r>5</r>
<shape>circle</shape>
</design>
<design>
<r>10</r>
<shape>triangle</shape>
</design>
</root>
Private
moXMLDoc
As
MSXML2.DOMDocument
Private
Sub
Command1_Click()
Set
moXMLDoc
=
New
MSXML2.DOMDocument
If
Not
moXMLDoc.Load(App.Path
&
"\test.xml")
Then
MsgBox
"load
error"
&
moXMLDoc.parseError.reason
Exit
Sub
End
If
Dim
oXMLNodeList
As
MSXML2.IXMLDOMNodeList
'多个节点
Set
oXMLNodeList
=
moXMLDoc.selectNodes("/root/design/shape")'****
Dim
oXMLNode
As
MSXML2.IXMLDOMNode
For
Each
oXMLNode
In
oXMLNodeList
Debug.Print
oXMLNode.Text
Next
'single
node
Set
oXMLNode
=
moXMLDoc.selectSingleNode("/root/design/shape")
Debug.Print
oXMLNode.Text
End
Sub