[xsd-users] Error Logging
Boris Kolpackov
boris at codesynthesis.com
Mon Apr 14 16:57:56 EDT 2008
Hi Ryan,
Prather, Ryan C SSgt USAF AFSPC SYAG/SED <Ryan.Prather at peterson.af.mil> writes:
> Is there a function that will convert the exception object to a STL
> string object?
Yes, you can use the std::ostringstream stream for that:
#include <sstream>
catch (const xml_schema::parsing& e)
{
std::ostringstream ostr;
ostr << e;
std::string str = ostr.str ();
}
> The function just takes two arguments an integer (error code) and
> string (error message). The string can be no longer than 60
> characters so I need to find a way to reformat the exceptions that
> XSD provides to something that is 60 characters or less.
I don't think you can do this without potentially loosing some
information. The xml_schema::parsing exception contains a list
of parsing errors and warnings. The above code will save them
all at once into the string. Instead you can iterate over them
and log one at a time:
catch (const xml_schema::parsing& e)
{
const xml_schema::diagnostics& d = e.diagnostics ();
for (xml_schema::diagnostics::const_iterator i = d.begin ();
i != d.end (); ++i)
{
const xml_schema::error& er = *i;
const std::string& msg = er.message ();
}
}
For more information on the xml_schema::parsing, xml_schema::diagnostics
and xml_schema::error types see Section 7.3, "Error Handling" in the
C++/Parser Getting Started Guide (I assume you are still using the
C++/Parser mapping):
http://codesynthesis.com/projects/xsd/documentation/cxx/parser/guide/#7.3
Boris
More information about the xsd-users
mailing list