Recurse XML file using vbscript

后端 未结 2 1149
借酒劲吻你
借酒劲吻你 2020-12-04 01:13

I am trying to use recursive technique to retrieve xml file. Can somebody help me doing that.

I am trying to read below xml, but not sure the depth of the nested tag

2条回答
  •  余生分开走
    2020-12-04 01:38

    VBScript provides you with tools to parse and process XML structures:

    Set xml = CreateObject("MSXML2.DOMDocument")
    xml.async = False
    xml.load "c:\path\to\foo.xml"
    WScript.Echo xml.xml
    

    You can access elements in the document tree using (among other things) the XPath query language:

    Set nodes = xml.selectnodes("//TestStep[@TSName='TestStep 2']")
    

    The above selects all TestStep nodes anywhere in the tree, which have an attribute TSName with a value TestStep 2.

    Once you have the node(s) you can read or change their attributes:

    WScript.Echo nodes.Length
    WScript.Echo nodes(0).parentNode.nodeName
    WScript.Echo nodes(1).parentNode.nodeName
    
    WScript.Echo nodes(0).text
    nodes(0).text = "foo"
    WScript.Echo nodes(0).text
    WScript.Echo xml.xml
    

提交回复
热议问题