Click here to Skip to main content
13,504,968 members
Click here to Skip to main content
Add your own
alternative version


13 bookmarked
Posted 21 Jul 2006

XML Parser

, 21 Jul 2006
Rate this:
Please Sign up or sign in to vote.
An article on an XML parser.


Well, this is my first article on the Internet. This article will show how to read/write XML documents.


It's a long time I have been working on networks. And I always had problems sending nested structures with multiple pointers over the network. Packing pointers and unpacking them was a real headache for me. Then came the idea of XML. Why not use XML to send data over the network? Although creating and reading XML docs is a little work on my part, life is much easy with it.

When I searched the Internet, I found xerces-c, a C library that could parse XML data. Well, it was not so simple using xerces-c (at least, I didn't find it easy). It had many complexities in it. So, I wrote this wrapper class using which I can generate XML data and also can read it back.

Using the code

I have attached a demo project showing how to read/write XML documents from/to files. Along with the code is a folder named "XML Files" which contains the xerces-c files supporting my wrapper.

The code is very easy to understand and use. It has got Set/Get functions through which we can easily generate XML documents. Here is the list of functions provided:

// Write the XML Document to a File
void  WriteToFile(char *filename);
// Generates an XML Document from an XML File
void   CreateDocumentFromFile(char *filename);
// Terminates XML Implementation
void   Terminate();
// Gets a float value from the tag Specified
float  GetFloatFromTag(char *);
// Gets a int value from the tag Specified
int    GetIntFromTag(char *tag);
// Creates an XML Document from a string
BOOL   CreateDocumentFromString(char *str);
// Destroys the Document not the Implementation 
void   DestroyDoc();
// Creates a new  XML Document from tag
BOOL   CreateDocument(char* data);
// Adds an element and add it to the Document
BOOL   CreateElement(char *node_tag,char* Node_Name, 
                     void *data, char DATA_TYPE,int len=0);
// Initializes Implantation
BOOL   Initialize();
// Gets a int array from the tag Specified
int*  GetIntegerArray(char *tag);
// Gets a float array from the tag Specified
float* GetFloatArray(char *tag);
// Gets a char string from the tag specified
char*  GetCharFromTag(char *tag);
// Converts the complete XML Document into a Char String
char*  GetXMLString();

These functions are self explanatory and are used well in the sample code. If you find any problems, you can always contact me.

Points of Interest

The most interesting part is the conversion of Unicode to ASCII . The most simplest way is to use ATL macros as used in the code. I know many people find it difficult to do so, but to me, it is the easiest thing to do :)).


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

Web Developer
Pakistan Pakistan
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionHello Ahmad, I'd like to ask how to extract data within child nodes Pin
luckiejacky745696927-Dec-12 17:54
memberluckiejacky745696927-Dec-12 17:54 
AnswerRe: Hello Ahmad, I'd like to ask how to extract data within child nodes Pin
Ahmad Hassan27-Dec-12 23:08
memberAhmad Hassan27-Dec-12 23:08 
QuestionWhat's wrong with TinyXml? Pin
Gilad Novik22-Jul-06 23:03
memberGilad Novik22-Jul-06 23:03 
AnswerRe: What's wrong with TinyXml? Pin
Anonymuos22-Jul-06 23:55
memberAnonymuos22-Jul-06 23:55 
GeneralRe: What's wrong with TinyXml? Pin
Gilad Novik23-Jul-06 9:06
memberGilad Novik23-Jul-06 9:06 
AnswerRe: What's wrong with TinyXml? Pin
Ahmad_Hassan23-Jul-06 4:45
memberAhmad_Hassan23-Jul-06 4:45 

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.180417.1 | Last Updated 21 Jul 2006
Article Copyright 2006 by Ahmad_Hassan
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid