Author Topic: TinyXml with Unicode thread  (Read 21921 times)

takeshimiya

  • Guest
TinyXml with Unicode thread
« on: December 20, 2005, 08:41:19 am »
Well, the problems of TinyXml and Unicode are still there.

I just found a piece of code that could help here:

wxtinyxml.cpp
Code
// 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;
}

wxtinyxml.h
Code
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

}


#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

If that doesn't helps, let's try another solution so we can end with this bug.
« Last Edit: December 20, 2005, 08:43:49 am by Takeshi Miya »

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: TinyXml with Unicode thread
« Reply #1 on: December 20, 2005, 08:43:42 am »
The problems of TinyXML and Unicode are there. Would you like to try my patch that fixes it all?
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

takeshimiya

  • Guest
Re: TinyXml with Unicode thread
« Reply #2 on: December 20, 2005, 08:44:55 am »
Of couse, I'll try that. :)

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: TinyXml with Unicode thread
« Reply #3 on: December 20, 2005, 08:47:05 am »
http://sourceforge.net/tracker/index.php?func=detail&aid=1385378&group_id=126998&atid=707418

http://sourceforge.net/tracker/index.php?func=detail&aid=1384347&group_id=126998&atid=707418

http://sourceforge.net/tracker/index.php?func=detail&aid=1382579&group_id=126998&atid=707418

There are a couple more smaller issues I fixed, but posting patches isn't seeming very worthwhile these days. Those 3 go back to 4 days ago. I have 9 other patches on SF right now, those 3 target Unicode specific problems.
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: TinyXml with Unicode thread
« Reply #4 on: December 20, 2005, 08:53:28 am »
Hang on, I'll get you a patch right now that fixes the "Code::Blocks v1.0" shows as "C v1" fix. I didn't and won't post it on SF because I was already told it won't get committed.
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

takeshimiya

  • Guest
Re: TinyXml with Unicode thread
« Reply #5 on: December 20, 2005, 09:16:18 am »
Thanks, I've noticed that thr C v1 bug with Unicode got introduced with autoversionator, right?

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: TinyXml with Unicode thread
« Reply #6 on: December 20, 2005, 09:17:51 am »
This one has most of my patches applied. At least all of the ones I'm "comfortable with." That includes all 13 I've posted at SourceForge plus a couple that I haven't.

It includes the 3 listed two posts up, but TortoiseSVN should figure that out and merge them without trouble.

Applies in codeblocks\src to rev1565.

Edit: There's a serious bug with copy/paste in what was linked here. It's fixed in the one 3 or 4 posts down.
« Last Edit: December 20, 2005, 10:48:45 am by 280Z28 »
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: TinyXml with Unicode thread
« Reply #7 on: December 20, 2005, 09:25:47 am »
Thanks, I've noticed that thr C v1 bug with Unicode got introduced with autoversionator, right?

Actually it's the unfortunate result of this thread :(
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5495
Re: TinyXml with Unicode thread
« Reply #8 on: December 20, 2005, 10:24:40 am »
Sam,

Could you please post all of them on sf ?

As said I will start nightly builds soon, and I will try also to build a 'user' patched build. That way people can experiment with pre-approved patches, which is good since this might give feedback on side effetcs before it makes the offical build.

I think he main debs are first sweating out there change of menu/toolbar/... stuff before they look back at the patches.


Lieven

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: TinyXml with Unicode thread
« Reply #9 on: December 20, 2005, 10:48:04 am »
Here is a complete patch of my code against rev 1565.

It includes my updates to the project file for building Unicode.

The only things in it that aren't on SF are maybe 2 lines where "<<" was replaced (see the diff for my syntax highlighting patch on SF for what I mean) and the rectangle copy/paste and drag/drop functionality in wxScintilla. Also, ctrl+mousewheel in my code does a pageup/pagedn instead of zooming. You'll find it amazingly useful.

http://www.280z28.org/CodeBlocks/patches/complete-rev1565u.patch
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: TinyXml with Unicode thread
« Reply #10 on: December 20, 2005, 10:55:24 am »
Hang on, I'll get you a patch right now that fixes the "Code::Blocks v1.0" shows as "C v1" fix. I didn't and won't post it on SF because I was already told it won't get committed.
Sam, the patch was turned down because it does not fix the bug. It is a patch that reverts Yiannis' changes in r1513. You are welcome  to fix the bug, but like I told you, the way to go is to modify the about box so it works with the modifications, not to revert appglobals.h.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline 280Z28

  • Regular
  • ***
  • Posts: 397
  • *insert unicode here*
Re: TinyXml with Unicode thread
« Reply #11 on: December 20, 2005, 11:07:35 am »
Hang on, I'll get you a patch right now that fixes the "Code::Blocks v1.0" shows as "C v1" fix. I didn't and won't post it on SF because I was already told it won't get committed.
Sam, the patch was turned down because it does not fix the bug. It is a patch that reverts Yiannis' changes in r1513. You are welcome  to fix the bug, but like I told you, the way to go is to modify the about box so it works with the modifications, not to revert appglobals.h.

I may toy with it later. For now, there are some major bugs that don't have solutions at all. As my code stands, that section falls under "don't fix what ain't broke." The former appglobals.h works in ANSI and unicode so I don't see why change it.  :? If someone changes it later and it still works and you're happy with it, then I guess that's fine too.
78 280Z, "a few bolt-ons" - 12.71@109.04
99 Trans Am, "Daily Driver" - 525rwhp/475rwtq
 Check out The Sam Zone :cool:

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: TinyXml with Unicode thread
« Reply #12 on: December 20, 2005, 06:43:20 pm »
Hello,

Regarding TinyXML & wxWidgets, I have found this article How To Use TinyXML With WxWidgets in the wxWiki that could be interesting.

Alternatively, if TinyXML seems to have problems with UNICODE, why not try the libxml2 library? It is mentioned on the wxWiki Using XML With WxWidgets and a wrapper wxxml2 exisits. Some info here about the libxml2 Encodings support.

Best wishes,
Michael

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: TinyXml with Unicode thread
« Reply #13 on: December 20, 2005, 06:50:58 pm »
How To Use TinyXML With WxWidgets
That's exactly what we are doing. :)
Quote
why not try the libxml2 library? It is mentioned on the wxWiki
If we were to use another xml library, we should be using the one built into wx. But that would mean we would have to rewrite an awful lot of code. Plus, the charm of tinyXML is that it is easy to use, small, and fast.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Michael

  • Lives here!
  • ****
  • Posts: 1608
Re: TinyXml with Unicode thread
« Reply #14 on: December 20, 2005, 07:12:18 pm »
How To Use TinyXML With WxWidgets
That's exactly what we are doing. :)

Ok, I see. Sorry :oops:.

why not try the libxml2 library? It is mentioned on the wxWiki
Quote
If we were to use another xml library, we should be using the one built into wx. But that would mean we would have to rewrite an awful lot of code. Plus, the charm of tinyXML is that it is easy to use, small, and fast.

Yes, I understand. Changing of xml library is worth if the code to be modified/rewritten is not too much and if really it is the only library that could solve the problem(s).

I have looked at TinyXML and it is an interesting piece of code. The only problem, I see is that it uses the Document Object Model (DOM). For small XML documents DOM is suitable, but for larger ones it could lead to high memory consumption (SAX would be a better alternative in this context).

Michael