xml parse with vbscript

前端 未结 2 747
野趣味
野趣味 2021-01-26 02:47

Hello i want to parse a specific info from xml. In that xml code i want to read ForexBuying of the US DOLLAR. I get msgbox when it\'s US DOLLAR but i want to see its ForexBuyin

2条回答
  •  梦毁少年i
    2021-01-26 03:35

    Just use XPath (properly, see here). As in:

    Dim oFS      : Set oFS      = CreateObject("Scripting.FileSystemObject")
    Dim sFSpec   : sFSpec       = oFS.GetAbsolutePathName("..\testdata\xml\26144567.xml")
    Dim objMSXML : Set objMSXML = CreateObject("Msxml2.DOMDocument")
    objMSXML.setProperty "SelectionLanguage", "XPath"
    objMSXML.async = False
    objMSXML.load sFSpec
    
    If 0 = objMSXML.parseError Then
       Dim sXPath   : sXPath       = "/Tarih_Date/Currency[CurrencyName = ""US DOLLAR""]/ForexBuying"
       Dim ndDollar : Set ndDollar = objMSXML.selectSingleNode(sXPath)
       If ndDollar Is Nothing Then
          WScript.Echo sXPath, "failed"
       Else
          WScript.Echo "ForexBuying:", ndDollar.text
       End If
    Else
       WScript.Echo objMSXML.parseError.reason
    End If
    

    output:

    cscript 26144567.vbs
    ForexBuying: 2.2829
    

提交回复
热议问题