I want to access only those nodes with property type = "file", how i can do that using vba
我想只访问属性类型=“文件”的那些节点,我怎么能用vba做到这一点
1 个解决方案
#1
0
Here is some working code. You must add a reference to Microsoft XML v6.0 in the tool menu of the VBA IDE for this to function.
这是一些工作代码。您必须在VBA IDE的工具菜单中添加对Microsoft XML v6.0的引用才能使其正常运行。
Sub SOExample()
'Made some changes here to make this valid XML
'This was missing some closing tags for file and entity
Const XML As String = "" & _
"" & _
"" & _
"" & _
""
Dim xmlDoc As DOMDocument60: Set xmlDoc = New DOMDocument60
xmlDoc.LoadXML XML
Dim ele As IXMLDOMNode
Dim eles As IXMLDOMNodeList: Set eles = xmlDoc.getElementsByTagName("*")
'Iterate each element and test to see if the name is File
For Each ele In eles
If ele.BaseName = "File" Then
'Print out the nodeName and the value
Debug.Print ele.nodeName, ele.Attributes(0).NodeValue
End If
Next
End Sub