Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

A simple STL based XML parser

, 16 May 2000
This is a small non-validating XML parser based purely on STL
#if !defined(XmlStream_H)
#define XmlStream_H

#include "XmlParser.h"
#include "XmlNotify.h"

#include <string>
#include <iostream>
using namespace std;



//////////////////////////////////////////////////////////////////////////////
// XmlStream
//
// Purpose: stores a string that contain start,end tag delimited value


class XmlStream :
	public string
{
	XmlNotify *			_subscriber;	// notification subscriber
public:

	XmlStream () :

		string (),
		_subscriber(NULL)

	{}

	virtual ~XmlStream ()
	{ 
		release(); 
	}

	// release resources
	bool create ()
	{
		return true;
	}

	bool create ( char * buffer, long len )
	{
		if ( buffer && len > 0 )
		{
			assign( buffer, len );
			return true;
		}
		else
			return false;
	}

	void release ()
	{
		erase( begin(), end() );
	}

	// notify methods
	void foundNode		( string & name, string & attributes );
	void foundElement	( string & name, string & value, string & attributes );

	void startElement	( string & name, string & value, string & attributes );
	void endElement		( string & name, string & value, string & attributes );

	// save/load stream
	bool save		( char * buffer );
	bool load		( char * buffer );

	// parse the current buffer
	bool parse			();
	bool parse			( char * buffer, long parseLength );
	bool parseNodes		( XmlParser & parser, char * buffer, long parseLength );

	// get/set subscriber
	bool hasSubscriber ()
	{
		if ( _subscriber )
			return true;
		else
			return false;
	}

	XmlNotify * getSubscriber ()
	{
		return _subscriber;
	}

	void setSubscriber ( XmlNotify & set )
	{
		_subscriber = &set;
	}


	// get ref to tag stream
	XmlStream & getTagStream ()
	{ return *this; }


	// get string ref
	string & str()
	{ return (string &) *this; }
};



#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

Share

About the Author

David Hubbard

United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 17 May 2000
Article Copyright 2000 by David Hubbard
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid