Click here to Skip to main content
13,357,973 members (57,142 online)
Click here to Skip to main content
Add your own
alternative version


28 bookmarked
Posted 21 Apr 2001

MXXMLWriter sample ported to VC++

, 21 Apr 2001
Rate this:
Please Sign up or sign in to vote.
Microsoft's MXXMLWriter sample that shows how to use SAX2 and MXXMLWriter is now ported to VC++ using ATL and C++, plus some nice additions.


The Simple API for XML (SAX) provides an alternate and more efficient way to parse XML files. MSDN has a ton of information on both the DOM and SAX APIs.

Last night I was reading through the documentation on how to use SAX and the MXXMLWriter to generate XML files. However, the only sample is written in VB and there was a request in the comments section for a working C++ sample. Since I figure that I have to eventually write code to do that, why not quickly port the sample over to VC++ as an exercise for myself and a service to others?

Project information

So here is the sample, written in C++ in conjunction with some light ATL (mainly to wrap Win32 API calls and for smart pointers). Here is what you need to build the sample:

  • Compiler: VC++ 6 (any service pack level should be fine)
  • Dependencies: MSXML 3.0 and up (you should install it prior to compile), ATL 3.0
  • Build: tested with debug and release builds with non-Unicode and Unicode configurations (so I guess it should run ok on Win9x?)

Some details

I spent some time to make the dialog resizable, unlike the VB sample where you really can't see the generated XML output if you are using a large file. Otherwise everything should behave very much like the VB sample. If you want to see the resizing code in action (which is another good exercise in itself), the following functions contain all the logic:

  • CMainDlg::Init() - set up
  • CMainDlg::OnSize() - actual resizing

The Try File and Try Demo functions are similar to the VB sample, except some minor modifications to set up the interface pointers and to get the data types correct. I would suggest that you download the VB sample as a reference.

In the VB sample, the left edit box is called "TextSource" and the right edit box is called "TextResult". In the VC++ port, I called them "Events" and "XML" respectively.

In the CMainDlg::OnTryDemo() function, I needed to use an ISAXAttributes and an IMXAttributes pointer to reference the SAXAttributes object that I created. That is because the addAttribute and clear methods are part of the IMXAttributes interface.

I have also included the test XML files that come with the original VB sample in the compressed file. The test1.xml file apparently contains a missing ">", so an error will be generated when you try that file. I am not sure whether this was intentional to test the error case or it was just a typo, but at least I have included some error checking in there, just to show that it works. :)


Credits go to Microsoft for providing a simple enough VB sample that I can read and understand.

This is my first article so I would very much appreciate any feedbacks.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Felix Cho
Web Developer
Canada Canada
No Biography provided

You may also be interested in...

Comments and Discussions

rna211727-Jun-12 7:43
memberrna211727-Jun-12 7:43 
GeneralMy vote of 4 Pin
jyl_hrb17-Apr-11 22:43
memberjyl_hrb17-Apr-11 22:43 
GeneralMy vote of 5 Pin
Andy Bantly16-Feb-11 7:35
memberAndy Bantly16-Feb-11 7:35 
QuestionstartElement help? Pin
VashSpaceCowboy28-Jan-09 13:37
memberVashSpaceCowboy28-Jan-09 13:37 
AnswerRe: startElement help? Pin
Felix Cho3-Feb-09 14:29
memberFelix Cho3-Feb-09 14:29 
GeneralRe: startElement help? Pin
VashSpaceCowboy3-Feb-09 14:34
memberVashSpaceCowboy3-Feb-09 14:34 
GeneralRe: startElement help? Pin
Felix Cho4-Feb-09 20:34
memberFelix Cho4-Feb-09 20:34 
GeneralRe: startElement help? Pin
VashSpaceCowboy5-Feb-09 6:06
memberVashSpaceCowboy5-Feb-09 6:06 
QuestionHow to gather XML details from Windows Clipboard??? Pin
gloriousgopi14-Feb-07 4:33
membergloriousgopi14-Feb-07 4:33 
GeneralCoCreateInstance() Pin
chinmaya00710-Oct-05 6:33
memberchinmaya00710-Oct-05 6:33 
GeneralRe: CoCreateInstance() Pin
Felix Cho10-Oct-05 8:10
memberFelix Cho10-Oct-05 8:10 
GeneralRe: CoCreateInstance() Pin
chinmaya00710-Oct-05 17:08
memberchinmaya00710-Oct-05 17:08 
GeneralRe: CoCreateInstance() Pin
Felix Cho11-Oct-05 8:40
memberFelix Cho11-Oct-05 8:40 
Generalwhich collection class to use ..... Pin
chinmaya00724-Sep-05 6:54
memberchinmaya00724-Sep-05 6:54 
GeneralRe: which collection class to use ..... Pin
Felix Cho25-Sep-05 10:49
memberFelix Cho25-Sep-05 10:49 
Questionhow to create a tree view of a xml file Pin
chinmaya0078-Sep-05 8:11
memberchinmaya0078-Sep-05 8:11 
AnswerRe: how to create a tree view of a xml file Pin
Felix Cho9-Sep-05 3:23
memberFelix Cho9-Sep-05 3:23 
GeneralWriting XML to a file Pin
Hara15-Oct-03 12:25
memberHara15-Oct-03 12:25 
GeneralRe: Writing XML to a file Pin
Felix Cho15-Oct-03 14:29
memberFelix Cho15-Oct-03 14:29 
GeneralYou could use this Pin
Anthony_Yio18-Jun-03 20:21
memberAnthony_Yio18-Jun-03 20:21 
QuestionWhy I cannot run this program on my machine? Pin
arthuryu18-Feb-02 18:27
memberarthuryu18-Feb-02 18:27 
AnswerRe: Why I cannot run this program on my machine? Pin
Felix Cho20-Feb-02 4:23
memberFelix Cho20-Feb-02 4:23 
GeneralThanks a lot! (question) Pin
Vejas10-Aug-01 1:49
memberVejas10-Aug-01 1:49 
GeneralRe: Thanks a lot! (question) Pin
yinx11-Sep-03 23:24
memberyinx11-Sep-03 23:24 
GeneralSAX in multithreaded context Pin
Alex Kravchenko4-May-01 8:03
memberAlex Kravchenko4-May-01 8:03 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 22 Apr 2001
Article Copyright 2001 by Felix Cho
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid