selectSingleNode using vbscript

后端 未结 1 2066
日久生厌
日久生厌 2020-12-06 22:51

Below is the structure of my xml file:


  
    
    

        
相关标签:
1条回答
  • 2020-12-06 23:14

    People who not use an error checking skeleton for XML work like this:

    Option Explicit
    
    Dim oFS    : Set oFS   = CreateObject("Scripting.FileSystemObject")
    Dim sFSpec : sFSpec    = oFS.GetAbsolutePathName(".\19194544.xml")
    Dim oXDoc  : Set oXDoc = CreateObject("MSXML2.DomDocument.6.0")
    oXDoc.setProperty "SelectionLanguage", "XPath"
    oXDoc.async = False
    oXDoc.load sFSpec
    
    If 0 = oXDoc.ParseError Then
       WScript.Echo sFSpec, "looks ok"
       Dim sXPath
       For Each sXpath In Array( _
           ".//configuration/appSettings/add[@key='LogsDirectory']/@value" _
       )
           Dim ndFnd : Set ndFnd = oXDoc.selectSingleNode(sXpath)
           If Not ndFnd Is Nothing Then
              WScript.Echo "found |" & ndFnd.xml & "|"
           Else
              WScript.Echo "not found |" & sXPath & "|"
           End If
       Next
    Else
       WScript.Echo oXDoc.ParseError.Reason
    End If
    

    also do bungee jumping without ropes.

    In your case the .ParseError.Reason

    The following tags were not closed: configuration, configuration.
    

    explains why there is no document to search in. At least this spares you the error you'd get when you try to assign the node returned from .selectSingleNode() to LogsDirectory without using Set.

    0 讨论(0)
提交回复
热议问题