热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在vba中访问XML节点属性-AccessXMLnodepropertyinvba

Iwanttoaccessonlythosenodeswithpropertytypefile,howicandothatusingvba我想只访问属性类型

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

推荐阅读
author-avatar
书友76075933
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有