// file      : examples/cxx/parser/hello/driver.cxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : not copyrighted - public domain

#include <string>
#include <iostream>

#include "hello.hxx"

using std::cerr;
using std::endl;
using std::string;


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

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

private:
  string greeting_;
};


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

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

    hello_p (string_p, string_p);


    // Parse the XML instance document.
    //
    hello_p._parse (argv[1],
                    "",       // root element namespace
                    "hello"); // root element name
  }
  catch (xml_schema::exception const& e)
  {
    cerr << e << endl;
    return 1;
  }
  catch (std::ios_base::failure const&)
  {
    cerr << "io failure" << endl;
    return 1;
  }
}
