Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

how to determine if a DocumentElement.Selectnodes is invalid or not present

$
0
0

Hi Guys,

I'm parsing a xml event log file for a certain eventid, and within that even i need to read the volumeinfo and componentinfo element. there is always a volumeinfo, but in certain cases an xml file won't have a component info.

I get an error in the script when i try to use the "componentInfo" element when its not present. (normal)

But i can't figure out (without cheating with try or on error) how to check if the returned array is valid?

I tried many things, and i can't find much documentation or examples on the web on how to address this

I tried isnull,isempty = nothing. with the (i) and without, with .text and without... i'm at a lost :(

Set xmlDoc=CreateObject("Microsoft.XMLDOM")
  XMLDoc.async = False
  XMLDoc.load(spath&fnlogfile)
  Set bkEventID =XMLDoc.documentElement.selectNodes("//Log/Event/System/EventID")  
  Set bkEventID =XMLDoc.documentElement.selectNodes("//Log/Event/System/EventID")
    Set bkcap =    XMLDoc.documentElement.selectNodes("//Log/Event/EventData/Data[@Name='VolumesInfo']")
  Set bkcaphv =  XMLDoc.documentElement.selectNodes("//Log/Event/EventData/Data[@Name='ComponentInfo']")   
    nbr=bkvolumes.length-1 

    For i=0 to nbr
    '.....
     If BkEventID(i).text="4" Then
      If bkcaphv(i).selectednode =Nothing Then  'if there is a component node
       WScript.Echo " node not found! "
      End If
     End If
    Next

Thanks!

    

Anthony Cartier-Info


Viewing all articles
Browse latest Browse all 15028

Trending Articles