1. Introduction
This article presents a simple GUI written in VC++.NET 2003, its main features include showing a XML file in a treeView and navigating through the XML data by using XPath expressions. It was mainly developed for my own need: from time to time in my work, I often felt it would be very convenient if I had a simple GUI to "preview" the XML file the system generated or received before I take steps further to implement any processing to it - it could be used as a tool to simply confirm "everything is okay". I could have used IE to open the XML file, but IE does not provide any "intelligent" navigation through the data. Sometimes, the XML file can be very big, therefore, it would be very helpful to combine the "viewing" function together with the "navigating" function. So here it is, using this small tool, I can view the XML file and also carry out a search in the file.
I hope you find this small tool useful and if you are just beginning your development work with VC++.NET, you can then use this example to study how easy to process XML files using MC++. You can also download the source code and maybe you will be motivated enough to add some more features to it, and I am sure you will then find it very helpful to your daily work.
2. Using the code
You may directly download the executable or you may download the source code and build it in Visual Studio.NET 2003. When you try to open a XML file, a file selection dialog will show up. After you select the file, you can build the treeview of the XML file by clicking "build
" button. You can then type XPath expressions to navigate in the tree.
XPath provides a more efficient way to locate data in a DOM tree. Just to make this small article complete, the following are some examples about how to use XPath expression (see the XML file in the screen shot):
/personnel/person
:
this will match all the person
nodes that are child nodes of personnel
and personnel
must be a root element node;
/personnel/person[email='one@foo.com']
:
this will find all the person
whose email is one@foo.com
.
I think the above examples are pretty much enough. If you provide a wrong expression, this small tool will show you some basic information, letting you know that something is wrong. Also, you can use the clear
button to start over.
3. That is it!
Okay, hope you find it useful, also look forward to seeing new features added to it!