• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 875
  • Last Modified:

How do I parse a values from a XML DOMDocument


I am working with Micrsoft Visual Basic for Applications (VBA) and calling a service that returns an XML document of type DOMDocument with the following schema:


I need to read through the document and when a specific set of Type, UID and Name tag values are found, read the Value tag value.  For example, if the Type equals zero, the UID equals 99999 and the Name equals Owner, I need to read the name stored in the Value tag pair.

The set of values I am looking for only occurs once in the document, but the there can be many <Column></Column> tag pairs to search through.

What I am looking for is the code required to extract the right Value from a DOMDocument that I have already read.

2 Solutions
Christian de BellefeuilleProgrammerCommented:
Save the result to a Text file (with extension .XML of course), then open it with Excel and parse it as you want.  If this is not what you want, please include a sample file so we can have something to start with...
I usually do this with a bit of javascript :-

var xmldom = new ActiveXObject('Microsoft.XMLDOM');
xmldom.async = false;

// load the file
xmldom.load("filename in here");

// check for errors
var pe = xmldom.parseError;
if(pe.errorCode!=0) {

// now we can get to work

var nodes = xmldom.selectNodes('/Reply/ProjectCodeValues/Columns/Column[***]/Value');

gives one or more nodes in an enumerable list. The bit withe the tree asterisks is (I can't get it clearly on one line) :-

Name="thenameyouwant" & Type="thetypeyouwant" & UID="theuidyouwant"

(which is called a predicate and selects only that Column whose elements have those specific values)

(The "selectNodes" method takes an XPath expression - go to w3c.org to get the standard)

If nodes is null or nodes.length=0 then you have not found what you want. If nodes.length is 1, then the value is given by the expression nodes[0].text;

If you are certain that you'll only ever select ONE node then you can use selectSingleNode(XPath) and test that against null. If not null then node.text gets the value.


Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now