selectNodesメソッドはXML文書から任意のノードリスト(IXMLDOMNodeList)を取得するメソッドです。
引数にはXPathで検索条件を指定します。XML文書はselectSingleNodeメソッドの紹介で使った
lcid.xmlを使います。
では、LCIDが「1000<=2000」であるlangName要素を取得して、その値を表示してみます。
Dim DOM, docRoot, node, nodeList, i
Set DOM = WScript.CreateObject("Microsoft.XMLDOM")
DOM.async = True
DOM.load("data\lcid.xml")
Set docRoot = DOM.documentElement
Set nodeList = _
docRoot.selectNodes("/LocaleId/language[(LCID > '1000') and (LCID <= '2000')]/langName")
For Each node In nodeList
WScript.Echo "言語名=" & node.firstChild.nodeValue
Next
WScript.Echo "---------------------------------------"
nodeList.reset()
For i=0 To nodeList.length-1
Set node = nodeList.nextNode()
WScript.Echo "言語名=" & node.firstChild.nodeValue
Next
Set node = Nothing
Set docRoot = Nothing
Set DOM = Nothing
結果は次のようになります。
C:\XML>cscript //nologo selectNodes.vbs
言語名=日本語
言語名=英語 (U.S.)
言語名=フランス語 (フランス)
言語名=ドイツ語 (ドイツ)
言語名=韓国語
---------------------------------------
言語名=日本語
言語名=英語 (U.S.)
言語名=フランス語 (フランス)
言語名=ドイツ語 (ドイツ)
言語名=韓国語
C:\XML>