Click here to Skip to main content
13,555,158 members
Click here to Skip to main content
Add your own
alternative version


34 bookmarked
Posted 14 May 2003

A simple C++ code generator (Sample Usage of my XML Wrapper class)

, 14 May 2003
Rate this:
Please Sign up or sign in to vote.
Generate C++ classes using XML & XSL

Sample Image - result.jpg


This is a small code generator. The user of this program is a programmer who writes his class in a similar structure time after time. This program is also an example for how to use the code of my article Wrapper class for DOM interface of windows SDK the title of which may be updated later, for its an ambiguous title.

How to compile the project using my wrapper of MS XML parser (IXMLDOMDocument ) for VC6.0 user

If you want to compile the classes for MS XML 3.x wrapper classes successfully under VC 6, you need the latest version of Microsoft Platform SDK, which can be downloaded from Microsoft’s website. After installing the Platform SDK downloaded from Microsoft, you shall use [tools|options…] to add your include path of Platform SDK in the directory list of VC++. Service pack 5 for Visual C++ is better.

How to generate code

VC++ 6.0 provides a serial class wizard which helps developers to generate the architecture code of MFC, ATL and so on. Microsoft Visual Studio also provides a standard way to write a new class wizard. Here, we demonstrate to implement such a function in XML/XSL. The principle to implement this function is very simple.


The user will input class name, the file name for header and source in the code generation dialog which is the main window of this project. If all information for your new class is inputted, you can push generate button in the dialog. The dialog collects all information of your new class into an XML tree in the memory. And then, calls the method Generate of CCodeGenerater, the new class is generated and saved to files with file names as given by the user.

The key feature of this program is the using of XML/XSL features in MS XML 3.x or 4.0. The principle is in the figure .The parameters can be given from CGetItemDlg by user. All parameters are packed into an XML tree in memory say CXMLParameterResult. As you know, the XML is loaded from disk file or string is stored in IXMLDOMDocument which is wrapped in CXMLFile. The format of CPP and header files used to generate new classes is located in 2 XSL files. CcodeGenerater loads all XSL files into memory and calls TransformNode method of IXMLDOMDocument to generate new class’ source code which is a string returned by TransformNode. And then, the CCodeGenerater writes the result to files according to user specific files.

UML diagram

The UML figure is the basic structure for this program. In the diagram, I omitted the CWinApp derived files and some utility files.

Note that the source code generated by this tool is an item class for template class CGroupItems, which is a special version of CArray with additional features that are used heavily in my program. Most functions in CGroupItems has the same form of functions in order to accomplish task.

About XSL

XSL is Extensible Stylesheet Language to interpret XML data. More detail information of XSL can be found in MSDN and

Using XML and XSL together, you can find enormous interesting usages. This program is just a small demonstration.


Thanks for a lot of people who have given me suggestions on writing articles in English. I’m not a native speaker and am eager to share my ideas. After I posted several articles to Code Project, some people figured out that my expression was not clear. I have tried to take more time to write good English.

Special thanks to Anthony, he is very kind to render my article, and articulate grammar and technical errors in my article. Thanks .:)


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

Johnson Zhou
Software Developer (Senior)
China China
I'm write program from 1990. My research field is CAG,CAD and Image processing. I select C/C++, ASP, Java, XML as my usaully developing tools. Occasional , write code in Delphi and VB. I'm using Visual C++ from 1996. If you have anything unclear, e-mail to Software Engineering and CAD is my mainly research program.

You also can reach me on msn:

You may also be interested in...


Comments and Discussions

GeneralI wrote a similar c++ code generator, but it's for command line. Pin
jfwan15-Jan-07 19:40
memberjfwan15-Jan-07 19:40 
GeneralRe: I wrote a similar c++ code generator, but it's for command line. Pin
xszxcvbnm15-Jul-09 1:52
memberxszxcvbnm15-Jul-09 1:52 
Generalthe xml.lib Pin
Pascal Levieux19-May-04 3:05
memberPascal Levieux19-May-04 3:05 
GeneralRe: the xml.lib Pin
surojitmukerji29-Jan-06 0:30
membersurojitmukerji29-Jan-06 0:30 
GeneralRe: the xml.lib Pin
Rachana Agrawal20-Aug-06 21:14
memberRachana Agrawal20-Aug-06 21:14 
Generalsuggestion Pin
YDLU5-Feb-04 6:35
memberYDLU5-Feb-04 6:35 
GeneralRe: suggestion Pin
YDLU5-Feb-04 9:37
memberYDLU5-Feb-04 9:37 
QuestionWhere is the project file? Pin
stempsoft30-Nov-03 13:37
memberstempsoft30-Nov-03 13:37 
GeneralWhere is 'xml_inc.h' Pin
Wolfgang Kleinschmit20-May-03 21:40
memberWolfgang Kleinschmit20-May-03 21:40 
GeneralRe: Where is 'xml_inc.h' Pin
Johnson Zhou21-May-03 2:08
memberJohnson Zhou21-May-03 2:08 
GeneralRe: Where is 'mis_xml_inc.h' ? Pin
haipengl2-Jun-04 6:51
memberhaipengl2-Jun-04 6:51 
GeneralSmall suggestions Pin
Jonathan de Halleux15-May-03 21:25
memberJonathan de Halleux15-May-03 21:25 
GeneralRe: Small suggestions Pin
SaurweinAndreas16-May-03 5:47
memberSaurweinAndreas16-May-03 5:47 
GeneralRe: Small suggestions Pin
Shmulik Flint19-May-03 18:20
memberShmulik Flint19-May-03 18:20 
GeneralRe: Small suggestions Pin
Johnson Zhou16-May-03 20:33
memberJohnson Zhou16-May-03 20:33 

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
Web02 | 2.8.180515.1 | Last Updated 15 May 2003
Article Copyright 2003 by Johnson Zhou
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid