title: Navigating XML nodes in VBScript, for a Dummy
body: <p>I am trying to write a script that will manipulate some data for me in an xml file.  I am pretty new to VBScript but have a VB.NET and VBA background, so I feel like I kind of know what I am doing.</p>
  
  <p>I thought there is probably a better way to navigate the file rather than a lot of calling InStr() or similar for each line to see if what I am looking for is there.  My initial idea was to use a few methods I have seen in VB.NET from System.XML, since I had seen node navigating functions and members in that.</p>
  
  <p>After investigating this, I cannot find any way to import a namespace (System.XML, or otherwise) into VBScript without it running on a webpage.  I decided to look for other options instead of spending more time searching for this.</p>
  
  <p>Turns out there are other ways to do what I want, using methods and objects that specifically deal with navigating nodes of an XML file.  I learned that some common examples of these "systems" (for lack of a better term, because I am sure that is improper) seem to be DOM and XPath.</p>
  
  <p>I started by investigating XPath (since I had seen XPath deemed superior to DOM in a few places, such as: <a href="https://stackoverflow.com/questions/1908526/traversing-all-nodes-in-an-xml-file-with-vbscript">Traversing all nodes in an XML file with VBScript</a>).  I could not find anything to discribe the basics of XPath in vbscript. There is lots on the syntax for paths and such, but I could find nothing that describes the very basics of how to actually call that syntax in VBScript to make use of it.  So I moved on to the next option.</p>
  
  <p>I then found many slightly different articles/questions/etc about DOM.  So I gave it a try.  Not a single one of them worked, all gave me errors.  Mostly, it just seemed that a DOM object is never loaded correctly.  Here are just a few of the methods I have tried for this:</p>
  
  <p>From <a href="http://msdn.microsoft.com/en-us/library/aa468547.aspx" rel="nofollow noreferrer">MSDN: a beginner's guide to XML DOM</a>:</p>
  
  <pre><code>Set objParser = CreateObject( "Microsoft.XMLDOM" )
  Dim xDoc As MSXML.DOMDocument
  Set xDoc = New MSXML.DOMDocument
  
  If xDoc.Load("C:\My Documents\cds.xml") Then
     msgbox("Success!")
  Else
     msgbox("Failure!")
  End If
  </code></pre>
  
  <p>This returned failure every time.</p>
  
  <p><a href="http://www.webdeveloper.com/forum/showthread.php?t=10172" rel="nofollow noreferrer">Based on another method</a>:</p>
  
  <pre><code>dim xmlDom
  set xmlDom = createobject("MSXML2.DOMDocument")
  xmlDom.async = false
  xmlDom.load ("C:\MyFileLocation\MyFile.xml")
  </code></pre>
  
  <p>and then I tried a few things to detect if it worked like message boxes for each node name in xmlDom.documentElement.</p>
  
  <p>I have tried so many other things I can't even remember most of them.</p>
  
  <p>I simply don't know what more I can try or why this isn't working for me. I am simply at a loss for what more I can try differently while still having syntax that COULD work.</p>
  
  <p>So my question is: How can I navigate an XML file using VBScript without the script being imbedded in a webpage or otherwise?  I need to know the extreme basics.</p>
  
  <p>I know my question likely seems stupid and ignorant since this should be easily available information, but I really cannot for the life of me find the basics I need to understand how to navigate nodes in ANY WAY using JUST VBScript (not in an html or asp file or something like that). </p>