[xsd-users] Questions about Default Value and Debug
Boris Kolpackov
boris at codesynthesis.com
Tue Apr 8 03:46:17 EDT 2008
Hi,
kun lv <lvkun2006 at gmail.com> writes:
> I have a large XSD file and generate code from
> it(with --generate-default-ctor ). I don't set all value for every element
> ,but when I run the program, It throw exception. I want to know if I can
> find a method allow me not set all value for every element.
No, there is no such method. The XSD-generated code has no way to
know what you think the default value should be for every type. I
suggest that you remove the --generate-default-ctor option. This
way the generated constructors will force you to specify the
required values and you won't get any exceptions.
> And I also want to know if the code generated by xsd could output the some
> log for debugging. The exception infomation is so brief that I can't find
> where cause the error.
You can use the --generate-ostream option which triggers generation
of std::ostream insertion operators for every generated type. This
way you can print the whole object model or any or its fragments
into a log.
> In the end, how can i output the structure to wstring. It seems like it can
> only use the stringstream not wstringstream.
You can instruct the compiler to use 'wchar_t' as the character type
instead of 'char' in the generate code with the '--char-type wchar_t'
option. This way the string-based types will all derive from
std::wstring instead of std::string. The stream insertion operators
will also use std::wostream instead of std::ostream.
If you don't want to change the character type in the generated code,
then you can use the following series of steps (may not work on all
platforms and/or for all character encodings):
type& r = ... / object model
std::ostringstream ostr;
ostr << r;
std::wostringstream wostr;
wostr << ostr.str ().c_str ();
std::wstring s (wostr.str ());
Boris
More information about the xsd-users
mailing list