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.

wxtinyxml.cpp

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 )
{
	Clear();
	location.Clear();
	
	wxTextInputStream txt(istream);
	
	wxString data;
	
	do
        {
            const wxString s = txt.ReadLine();

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

        } while (1);

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

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



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

}

wxtinyxml.h

Code: Select all

#ifndef __WXTINYXML_H__
#define __WXTINYXML_H__

#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

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

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

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

};


#endif

Posted: Sun Jun 26, 2005 11:31 pm
by Ryan Norton
I believe this is the link to tinyxml - http://www.grinninglizard.com/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 ...