[xsd-users] Help me: How do I redirect the exception message from console output to a memory buffer

James Mei jxmei3 at gmail.com
Sun Oct 18 05:26:28 EDT 2009


Hi Boris


You can use std::ostringstream to serialize the diagnostics to a string.
>

Do you have an example on doing it ?

You can also programmatically access each parsing/serialization diagnostics

message by catching the xml_schema::parsing and/or xml_schema::validation
> exceptions and using their accessors to extract this information. For
> details, see Section 3.3, "Error Handling" in the C++/Tree Mapping User
> Manual:
>
>
> http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#3.3
>

I have tried doing it, it seems like I did something wrong in the
auto_ptr<SCL> and it will not compile.

#include <iostream>
#include <fstream>
#include "scl\SCL.hxx"

using namespace std;

class error_handler
{
public:
  struct severity
  {
    enum value
    {
      warning,
      error,
      fatal
    };
  };

  virtual bool
  handle (const std::basic_string<char>& id,
          unsigned long line,
          unsigned long column,
          severity,
          const std::basic_string<char>& message) = 0;

  virtual
  ~error_handler ();
};
//implementation
bool
  error_handler::handle (const std::basic_string<char>& id,
          unsigned long line,
          unsigned long column,
          severity,
          const std::basic_string<char>& message)
{
     cout << id << message << endl;
}


int main (int argc, char* argv[])
{
  try
  {
    using namespace SC_SCL;
//I am trying to use the following
// ::std::auto_ptr< ::SC_SCL::SCL >
//  SCL_ (const ::std::string& u,
//        ::xml_schema::error_handler& h,
//        ::xml_schema::flags f,
//        const ::xml_schema::properties& p)
    error_handler *eh;
//compilation error Could not find a match for 'SCL_(char
*,xml_schema::error_handler *,const unsigned long,int)'
    auto_ptr<SCL> h (SCL_(argv[1], (::xml_schema::error_handler *)eh, 0,
NULL));  //not using xml_schema::flags::dont_validate

    h.get()->Header().revision("abc");
    xml_schema::namespace_infomap map;

    map[""].name = "http://www.iec.ch/61850/2003/SCL";
    map[""].schema = "SCL.xsd";

    ofstream outfile(argv[2], ios::out);
    SCL_ (outfile, *h, map);
  }
  catch (const xml_schema::exception& e)
  {
    cerr << e << endl;
    return 1;
  }
}

May I know what is the correct way to implement the "error_handler" ?

Cheers


More information about the xsd-users mailing list