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:
void WriteToFile(char *filename);
void CreateDocumentFromFile(char *filename);
float GetFloatFromTag(char *);
int GetIntFromTag(char *tag);
BOOL CreateDocumentFromString(char *str);
BOOL CreateDocument(char* data);
BOOL CreateElement(char *node_tag,char* Node_Name,
void *data, char DATA_TYPE,int len=0);
int* GetIntegerArray(char *tag);
float* GetFloatArray(char *tag);
char* GetCharFromTag(char *tag);
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 ).