在 VBSCript 中读取 XML 文件节点 [英] Reading XML file nodes in VBSCript

查看:33
本文介绍了在 VBSCript 中读取 XML 文件节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以下格式的 XML 文件..我在这里做的是遍历公共节点中的文件并循环遍历它们..问题是公共节点内的注释抛出一个错误,表示 getAttribute("name") 不受支持..谁能告诉我如何遍历子节点并避免阅读注释行.

I have a XML file in the below format..What I am doing here is going through the files in the common node and looping through them ..The issue is the comments inside the common node throws an error which says the getAttribute("name") is not supported ..Can someone please tell me how to loop through child nodes and avoid reading the commented lines.

Set objNodeList = xmlDoc.getElementsByTagName("Common")

For each comNodeItem in objNodeList

   On Error Resume Next
    for each fileNodeItem in comNodeItem.ChildNodes        

        fileName = fileNodeItem.getAttribute("name")   



  next

    <Common>
        <!-- Test Comment -->
        <file name="Test1.css"/>
            <file name="Test2.css"/>
    </Common>
    <Common>
        <!-- Test Comment -->
        <file name="Test3.css"/>
            <file name="Test4.css"/>
    </Common>

推荐答案

您可以考虑尝试以下代码片段.

You may consider trying the following code snippet.

Set xmlDoc = CreateObject("MSXML.DomDocument")
xmlDoc.LoadXML "<Common><!-- Test Comment --><file name='Test1.css'/><file name='Test2.css'/></Common>"
For Each xmlFile in xmlDoc.selectNodes("//file")
    MsgBox xmlFile.getAttribute("name")
Next

这篇关于在 VBSCript 中读取 XML 文件节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆