[xsd-users] unicode support

Boris Kolpackov boris at codesynthesis.com
Mon Jul 31 06:30:19 EDT 2006


Remsy Schmilinsky <rschmilinsky at yahoo.ca> writes:

> Hi. I modified the parser-rules.make for the hello example to enable
> --char-type wchar_t option because I need my application to support
> unicode.
>
> Now the driver application won't compile, I get the following errors.
> What do I have to change? It looks like string is no longer the
> appropiate data type at line 52 of driver.cxx. The application works
> fine if I don't activate char-type option as wchar_t. Please help.


When compiled with wchar_t, the generated code uses wchar_t instead
of char and std::wstring instead of std::string. Your code will need
to account for this. Here is a modified driver.cxx from the hello
example that is meant to be used with the --char-type wchar_t. We
will also add this example to the next version.

hth,
-boris


#include <string>
#include <iostream>
#include <fstream>

#include "hello.hxx"

using std::wcerr;
using std::endl;
using std::wstring;


struct hello_parser: hello_type<void,
                                wstring, // greeting
                                wstring> // name
{
  virtual void
  greeting (const wstring& greeting)
  {
    greeting_ = greeting;
  }

  virtual void
  name (const wstring& name)
  {
    wcerr << greeting_ << ", " << name << "!" << endl;
  }

private:
  wstring greeting_;
};


int
main (int argc, char* argv[])
{
  if (argc != 2)
  {
    wcerr << "usage: " << argv[0] << " hello.xml" << endl;
    return 1;
  }

  try
  {
    // Construct the parser.
    //
    xml_schema::string string_p;
    hello_parser hello_p;

    hello_p.greeting_parser (string_p);
    hello_p.name_parser (string_p);


    // Parse the XML instance document. The second argument to the
    // document's constructor is the document's root element name.
    //
    xml_schema::document<void> doc_p (hello_p, L"hello");

    //
    //
    std::ifstream ifs (argv[1]);

    doc_p.parse (ifs);
  }
  catch (const xml_schema::exception& e)
  {
    wcerr << e << endl;
    return 1;
  }
  catch (const std::ios_base::failure&)
  {
    wcerr << "io failure" << endl;
    return 1;
  }
}

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20060731/3abcc5e9/attachment.pgp


More information about the xsd-users mailing list