How do I parse a values from a XML DOMDocument

Posted on 2009-04-28
Last Modified: 2013-11-10

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.

Question by:bobsegrest
    LVL 10

    Accepted Solution

    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...
    LVL 27

    Assisted Solution

    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 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

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Introduction In my previous article ( I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
    Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
    The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
    The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now