Query XML DOM Nodes (C-C++)

 

MSXML provides two DOM methods that allow you to query a node or a set of nodes in an XML DOM object: SelectNodes and SelectSingleNode. You specify the node or nodes of interest in an XPath expression, which is taken as the input to these methods.

In this C/C++ demonstration, we assume that you have some understanding of XPath expressions.

This project uses or creates the following files.

ComponentDescription
Source: queryNodes.cppSelects both a single node and a node-set from a DOM object.
Resource: stocks.xmlAn XML data file.
OutputWhen you build and run the queryNodes project, you should get this output in a console window.

To create the queryNodes project in Visual C++

  1. Create a Win32 console application in Visual C++. For detailed instructions on how to do this, see Set Up My Visual C++ Project. Name the project queryNodesProj.

Next, we'll add the source code for the queryNodes project.

XPath Reference

Show: