Page 1 of 1

wxTiXmlDocument: TinyXML + wxWidgets streams

Posted: Sat Feb 26, 2005 8:42 pm
by ahz_
The only problem I noticed so far is that SaveFile() does not format the XML nicely.


Code: Select all

// This crude code is for using wxWidget streams with TinyXML.  
// This is useful, for example, for loading and saving XML directly
// into a ZIP file (with the new ZIP streams in 2.5.4).

// Copyright (c) 2005 Andrew Ziem. All rights reserved.
// This code is licensed under the three licenses:  wxWindows Library Licence, Version 3;
// Zlib license (like TinyXML); and the GNU General Public License version 2 or later.

#include "wxtinyxml.h"

bool wxTiXmlDocument::LoadFile( wxInputStream &istream )
	wxTextInputStream txt(istream);
	wxString data;
            const wxString s = txt.ReadLine();

            if ( istream.Eof() && s.empty() )
	    data += s;

        } while (1);

	Parse( wxConvCurrent->cWX2MB(data), 0, TIXML_ENCODING_UTF8 );

	if (  Error() )
		return false;
		return true;

bool wxTiXmlDocument::SaveFile (wxOutputStream &ostream)
	wxTextOutputStream txt(ostream);
#error not implemented
	TiXmlOutStream outs;
	StreamOut (&outs);
	const char *c =  outs.c_str();
	txt << wxString(c, wxConvUTF8);



Code: Select all

#ifndef __WXTINYXML_H__
#define __WXTINYXML_H__

#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop

#ifndef WX_PRECOMP
    #include "wx/wx.h"

#include "tinyxml.h"
#include "wx/txtstrm.h"

class wxTiXmlDocument : public TiXmlDocument
bool LoadFile( wxInputStream &istream );
bool SaveFile( wxOutputStream &ostream );



Posted: Sun Jun 26, 2005 11:31 pm
by Ryan Norton
I believe this is the link to tinyxml -

Posted: Thu Nov 24, 2005 6:53 pm
by ghostd0g
jfyi, there seems to be missing a proper return statement in wxTiXmlDocument::SaveFile. anyway thx for this useful snippet. a USE_STL version would be great though ...