Click here to Skip to main content
Licence 
First Posted 21 Apr 2001
Views 133,690
Bookmarked 25 times

MXXMLWriter sample ported to VC++

By | 21 Apr 2001 | Article
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.

Introduction

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. :)

Conclusion

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.

License

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

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 4 Pinmemberjyl_hrb21:43 17 Apr '11  
GeneralMy vote of 5 PinmemberAndy Bantly6:35 16 Feb '11  
QuestionstartElement help? PinmemberVashSpaceCowboy12:37 28 Jan '09  
AnswerRe: startElement help? PinmemberFelix Cho13:29 3 Feb '09  
GeneralRe: startElement help? PinmemberVashSpaceCowboy13:34 3 Feb '09  
GeneralRe: startElement help? PinmemberFelix Cho19:34 4 Feb '09  
GeneralRe: startElement help? PinmemberVashSpaceCowboy5:06 5 Feb '09  
QuestionHow to gather XML details from Windows Clipboard??? Pinmembergloriousgopi3:33 14 Feb '07  
GeneralCoCreateInstance() Pinmemberchinmaya0075:33 10 Oct '05  
GeneralRe: CoCreateInstance() PinmemberFelix Cho7:10 10 Oct '05  
GeneralRe: CoCreateInstance() Pinmemberchinmaya00716:08 10 Oct '05  
GeneralRe: CoCreateInstance() PinmemberFelix Cho7:40 11 Oct '05  
Generalwhich collection class to use ..... Pinmemberchinmaya0075:54 24 Sep '05  
GeneralRe: which collection class to use ..... PinmemberFelix Cho9:49 25 Sep '05  
Questionhow to create a tree view of a xml file Pinmemberchinmaya0077:11 8 Sep '05  
AnswerRe: how to create a tree view of a xml file PinmemberFelix Cho2:23 9 Sep '05  
GeneralWriting XML to a file PinmemberHara11:25 15 Oct '03  
GeneralRe: Writing XML to a file PinmemberFelix Cho13:29 15 Oct '03  
GeneralYou could use this PinmemberAnthony_Yio19:21 18 Jun '03  
QuestionWhy I cannot run this program on my machine? Pinmemberarthuryu17:27 18 Feb '02  
AnswerRe: Why I cannot run this program on my machine? PinmemberFelix Cho3:23 20 Feb '02  
GeneralThanks a lot! (question) PinmemberVejas0:49 10 Aug '01  
GeneralRe: Thanks a lot! (question) Pinmemberyinx22:24 11 Sep '03  
GeneralSAX in multithreaded context PinmemberAlex Kravchenko7:03 4 May '01  
GeneralRe: SAX in multithreaded context PinmemberFelix Cho8:05 4 May '01  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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 | Mobile
Web04 | 2.5.120517.1 | Last Updated 22 Apr 2001
Article Copyright 2001 by Felix Cho
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid