Click here to Skip to main content
16,011,685 members
Articles / Web Development / HTML

XML Parser Demo

Rate me:
Please Sign up or sign in to vote.
4.71/5 (21 votes)
29 Oct 2000CPOL 339.3K   5.1K   46   50
Using the Microsoft XML (MSXML) parser.

Introduction

In an attempt to learn how to exploit XML (eXtensible Mark-up Language) within my applications, I have found a very few demonstration applications to assist me in getting started. The documentation and examples in the Platform SDK for using the Microsoft XML Parser (built into Internet Explorer 4+, although I'm using IE5) all seem to be for Visual Basic/VBScript and not for C++/MFC.

In this sample application I've simply tried to parse a XML file and visualise it as a basic tree view. The code recursively walks through both then ELEMENTS and ATTRIBUTES of the document. Some of the known element types are given an identifying icon and some of the contents/values are expressed too.

Included within the .Zip file is my first XML file including a DTD (Document Type Definition).

XML Parser
Figure 1 - Sample XML Parser Dialog

Parsing errors detected by the MSXML object are displayed within a message box and locate the problem location within the XML document.

 

Parser Error
Figure 2 - Parser Error Report

See the source code for the parser code - it's quite simple.

If you're interested, the long term aim of this file is to provide an externally configurable definition for toolbar and menu layouts within my applications. Due to the nature of the customer, end-user customisation is not applicable yet the specifications for what is wanted is likely to come through after I've left the project.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Product Manager
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: looking for the XML tutorial FOR Beginners Pin
Felix Rivera9-Nov-00 11:49
Felix Rivera9-Nov-00 11:49 
GeneralRe: looking for the XML tutorial FOR Beginners Pin
9-Nov-00 17:11
suss9-Nov-00 17:11 
GeneralMSXML 3.0 Final Pin
Brad Bruce4-Nov-00 4:06
Brad Bruce4-Nov-00 4:06 
GeneralWorth the effort Pin
Adrian31-Oct-00 19:17
Adrian31-Oct-00 19:17 
GeneralUse XML4C from Apache/IBM Pin
Jamie Nordmeyer31-Oct-00 6:27
Jamie Nordmeyer31-Oct-00 6:27 
GeneralRe: Use XML4C from Apache/IBM Pin
Joshua Nussbaum1-Nov-00 12:02
Joshua Nussbaum1-Nov-00 12:02 
GeneralRe: Use XML4C from Apache/IBM Pin
Jamie Nordmeyer1-Nov-00 12:43
Jamie Nordmeyer1-Nov-00 12:43 
GeneralRe: Use XML4C from Apache/IBM Pin
Leo Davidson3-Nov-00 1:13
Leo Davidson3-Nov-00 1:13 
I recently tried XML4C / Xerces and spent a lot of time and effort with it. In the end I gave up and went to LibXml ( http://xmlsoft.org ) which seems a lot nicer so far, at least depending on which features of XML you need.

Major problems I had with XML4C / Xerces were:

* Almost complete lack of documentation. It's fine to say "read the XML and DOM specs" but a lot of their classes are nothing to do with the XML and DOM specs. What little documentation there is is usually just some comments from the header files, if you're lucky -- usually nothing. (It's free so they don't have to make my life easy and I'm not complaining, just saying that I found it unusable in places.)

* No "save" method which means you have to write your own code to save XML to files. (There are some classes to help you do this but they are not documented. I got them to work after a lot of web searching and hacking through the source code, and I have to say I really didn't like the way things worked, but that's a matter of style / preference. Either way, you're looking at a lot of effort if you want to save XML to files.)

* The nail in the coffin was when I found that I was getting random errors which I think traced back to the fact that the Xerces DLL was calling "new" and expecting me to call "delete". This isn't safe if you're linking to a different version of the C Runtime to the DLL (which I was). Although I could've fixed the problem by recompiling the DLL (creating a version incompatible with other programs), this mistake (rather than providing a Delete/Free function stub in the DLL) seemed yet another sign of bad design and I figured that I'd wasted enough of my life fighting this thing already.

Xerces does seem to be a big, serious XML implementation so I'm sure it's great for some people. Personally, I'm very happy with LibXml ( http://xmlsoft.org ).

GeneralRe: Use XML4C from Apache/IBM Pin
20-Aug-01 7:53
suss20-Aug-01 7:53 
GeneralXML Version 3 beta (September) Pin
Ray Hayes31-Oct-00 1:36
Ray Hayes31-Oct-00 1:36 
GeneralIt is not Working Properly Pin
VenkataKrishnan.K31-Oct-00 0:30
sussVenkataKrishnan.K31-Oct-00 0:30 
GeneralRe: It is not Working Properly Pin
Ray Hayes31-Oct-00 0:49
Ray Hayes31-Oct-00 0:49 
GeneralRe: It is not Working Properly Pin
Brad Bruce31-Oct-00 1:42
Brad Bruce31-Oct-00 1:42 
GeneralCompile Error Pin
niv30-Oct-00 23:23
niv30-Oct-00 23:23 
GeneralRe: Compile Error Pin
Ray Hayes30-Oct-00 23:46
Ray Hayes30-Oct-00 23:46 
GeneralRe: Compile Error: Include the Following Lines Pin
VenkataKrishnan.K31-Oct-00 0:48
sussVenkataKrishnan.K31-Oct-00 0:48 
GeneralRe: Compile Error: Include the Following Lines Pin
EZ31-Oct-00 9:50
EZ31-Oct-00 9:50 
GeneralRe: Compile Error: Include the Following Lines Pin
Adrian31-Oct-00 19:18
Adrian31-Oct-00 19:18 
GeneralRe: Compile Error: Include the Following Lines Pin
Praveen KR9-May-01 18:03
Praveen KR9-May-01 18:03 
GeneralRe: Compile Error: Include the Following Lines Pin
11-May-01 0:38
suss11-May-01 0:38 
GeneralRe: Compile Error: Include the Following Lines Pin
sterding7-Apr-02 2:07
sterding7-Apr-02 2:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.