Skip the first node and repeat from the second node xml in VBS

Anyone can suggest a better way to skip the first appearance of the first XML node and start the iteration from the second node. In the example below, I want to skip the first appearance of node "word" and start iterating the form of the second appearance of node "word". Thanks in advance.

<words> <word> <name>Vowel</name> </word> <word> <value>a</value> </word> <word> <value>Vowel</value> </word> </words> 
+5
source share
1 answer

child nodes are collected in the childNodes collection. To skip nodes, you need to loop on childNodes by number / index, rather than a more frequent one for each approach. In code:

 Option Explicit Dim sXPath : sXPath = "/words" Dim oXDoc : Set oXDoc = CreateObject("Msxml2.DOMDocument.6.0") oXDoc.setProperty "SelectionLanguage", "XPath" oXDoc.async = False oXDoc.load "35359922.xml" If 0 = oXDoc.ParseError Then Dim ndWords : Set ndWords = oXDoc.selectSingleNode(sXPath) If ndWords Is Nothing Then WScript.Echo "|", sXPath, "| not found" Else WScript.Echo "found " & ndWords.childNodes.length & " nodes." Dim i For i = 1 To ndWords.childNodes.length - 1 WScript.Echo i, ndWords.childNodes(i).text Next End If Else WScript.Echo oXDoc.ParseError.Reason End If 

output:

 cscript 35359922.vbs found 3 nodes. 1 a 2 Vowel 
+1
source

Source: https://habr.com/ru/post/1242847/


All Articles