[xsd-users] Questions about Default Value and Debug

Boris Kolpackov boris at codesynthesis.com
Tue Apr 8 05:52:57 EDT 2008


Hi,

kun lv <lvkun2006 at gmail.com> writes:

> But I already add the "--char-type wchar_t'" option, the string type
> is converted to wstring,but the stream insertion operators have not
> changed.

I just tried to compile hello.xsd that comes with the XSD distribution
using the following command line:

xsd cxx-tree --char-type wchar_t --generate-ostream hello.xsd

After that I opened the generated hello.hxx file and saw the following
declaration for the stream insertion operator:

::std::wostream&
operator<< (::std::wostream&, const hello_t&);

This operator should allow me to do the following:

hello_t& h = ...

std::wostringstream ostr;
ostr << h;
std::wstring s (ostr.str ());

Perhaps you are confusing the stream insertion operators that are
generated using --generate-ostream with the serialization operators
and functions generated using --generate-serialization. The stream
insertion operators dump the object model in a human readable text
format which is useful for debugging, etc. The serialization
operators save the object model in XML. Because XML can be encoded
using various encodings (e.g., ASCII, UTF-8, UTF-16, UTF-32), the
resulting output is treated by serialization functions as a sequence
of bytes. This is why serialization functions output to std::ostream
even when you specify '--char-type wchar_t'. If you make sure that
your XML is in the same encoding and endianness as what's in wchar_t
(e.g, UTF-32LE), then you can initialize a std::wstring instance with
a memory buffer that holds your XML document.

Boris




More information about the xsd-users mailing list