18 #ifndef VCSN_XML_HANDLERS_BASE_HXX
19 # define VCSN_XML_HANDLERS_BASE_HXX
21 # include <xercesc/util/XMLString.hpp>
33 ErrHandler::warning (
const xercesc::SAXParseException& exc)
35 char* msg = xercesc::XMLString::transcode(exc.getMessage());
36 std::cerr <<
"Warning: " << msg << std::endl;
37 xercesc::XMLString::release(&msg);
41 ErrHandler::error (
const xercesc::SAXParseException& exc)
43 char* msg = xercesc::XMLString::transcode(exc.getMessage());
44 std::cerr <<
"Error: " << msg << std::endl;
45 xercesc::XMLString::release(&msg);
49 ErrHandler::fatalError (
const xercesc::SAXParseException& exc)
51 char* msg = xercesc::XMLString::transcode(exc.getMessage());
52 std::cerr <<
"Fatal error: " << msg << std::endl;
53 xercesc::XMLString::release(&msg);
59 void token(
const XMLCh*
const localname)
61 std::cerr <<
"Unexpected token: " << xmlstr(localname) << std::endl;
64 void attrs(
const XMLCh*
const localname,
65 const std::string& name,
66 const std::string& value)
68 std::cerr <<
"Unexpected value of `" << name <<
"' (" << value <<
") in token: " << xmlstr(localname) << std::endl;
72 void missattrs(
const XMLCh*
const localname,
73 const std::string& name)
75 std::cerr <<
"Missing attribute `" << name <<
" in token: " << xmlstr(localname) << std::endl;
79 void notletter(
const std::string& str)
81 std::cerr << str <<
" is not a letter" << std::endl;
89 Handler::Handler (xercesc::SAX2XMLReader* parser,
90 xercesc::DefaultHandler& root,
99 Handler::Handler (xercesc::SAX2XMLReader* parser,
109 Handler::startElement (
const XMLCh*
const uri,
110 const XMLCh*
const localname,
111 const XMLCh*
const qname,
112 const xercesc::Attributes& attrs)
116 std::cout << std::string(2 * indent_,
' ') <<
"<" << xmlstr(localname) <<
">" << std::endl;
118 start(uri, localname, qname, attrs);
122 Handler::endElement (
const XMLCh*
const uri,
123 const XMLCh*
const localname,
124 const XMLCh*
const qname)
126 end(uri, localname, qname);
128 std::cout << std::string(2 * indent_,
' ') <<
"</" << xmlstr(localname) <<
">" << std::endl;
135 UnsupHandler::UnsupHandler (xercesc::SAX2XMLReader* parser,
137 : Handler(parser, root),
143 UnsupHandler::start (
const XMLCh*
const,
146 const xercesc::Attributes&)
152 UnsupHandler::end (
const XMLCh*
const,
154 const XMLCh*
const localname,
161 std::cerr << std::string((indent_ + 1) * 2,
' ') <<
"unsupported token: " << xmlstr(localname) << std::endl;
166 parser_->setContentHandler(&root_);
173 #endif // !VCSN_XML_HANDLERS_BASE_HXX