Search code examples
xmlvb6

DOMDocument60 Node List


I am having an issue trying to get the Node List to get populated correctly.

Dim xmlDoc As New MSXML2.DOMDocument60

Set xmlNodeLst = xmlDoc.selectNodes("TagToGetNodes")

This issue is the XML Tag itself looks like this:

TagToGetNodes xmlns="http://www.randomlink.com/TagToGetNodes"

If this is not in the tag, xmlns="http://www.randomlink.com/TagToGetNodes - the code above works 100% of the time. With that in the tag, fails everytime.

Any thoughts?


Solution

  • Your sample node has a Namespace. If you give the Namespace a name:

    xmlDoc.setProperty "SelectionNamespaces", "xmlns:YourName='http://www.randomlink.com/TagToGetNodes'"
    

    Then you can modify your XPath to include the given name allowing the nodes to be selected:

    Set xmlNodeLst = xmlDoc.selectNodes("YourName:TagToGetNodes")