Click here to Skip to main content
15,884,628 members
Articles / Programming Languages / XML

Read and Write application parameters in XML

Rate me:
Please Sign up or sign in to vote.
4.38/5 (33 votes)
30 Jun 20034 min read 1.6M   6.8K   141  
This article provides an easy way to load and save the parameters of an application in XML format.
#if !defined(XmlUtil_H)
#define XmlUtil_H


/////////////////////////////////////////////////////////////////////////
// define tag markers

#define idTagLeft	"<"
#define idTagRight	">"
#define idTagEnd	"</"
#define idTagNoData "/>"


#define idTagLeftLength		1
#define idTagRightLength	1
#define idTagEndLength		2


#include <string>

//////////////////////////////////////////////////////////////////////////////////
// XmlUtil
//
// Purpose:		provides xml utility methods

class XmlUtil
{

	// tag helper methods
	static std::string getStartTag ( std::string & text )
	{
		std::string tag = idTagLeft;
		tag += text;
		tag += idTagRight;

		return std::string(tag);
	}

	// static helper methods
	static std::string getEndTag ( std::string & text )
	{
		std::string tag = idTagEnd;
		tag += text;
		tag += idTagRight;

		return std::string(tag);
	}

	static std::string getStartTag ( const char *text )
	{
		std::string tag = idTagLeft;
		tag += text;
		tag += idTagRight;

		return std::string(tag);
	}

	static std::string getEndTag ( const char *text )
	{
		std::string tag = idTagEnd;
		tag += text;
		tag += idTagRight;

		return std::string(tag);
	}
};


#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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


Written By
Web Developer
China China
I've been living & working in Tokyo since 2000 . I'm currently working in Gentech Corp. (www.gen.co.jp), developing computer vision applications, especially in the field of face detection.

I've been interested in C++ for quite a while and recently discovered Ruby.

My hobbies are trekking, japanese food, yoga & onsens.

Comments and Discussions