beefed up error reporting a bit

This commit is contained in:
jez_higgins 2004-05-12 19:38:54 +00:00
parent ad69b4658e
commit 3110715864

View file

@ -32,27 +32,31 @@ class SAX2PYX : public SAX::DefaultHandler
virtual void warning(const SAX::SAXParseException& e) { fatalError(e); } virtual void warning(const SAX::SAXParseException& e) { fatalError(e); }
virtual void error(const SAX::SAXParseException& e) { fatalError(e); } virtual void error(const SAX::SAXParseException& e) { fatalError(e); }
void setParser(SAX::XMLReader<std::string>& parser) { parser_ = &parser; }
private: private:
std::string escape(const std::string& str) const; std::string escape(const std::string& str) const;
SAX::XMLReader<std::string>* parser_;
}; // class SimpleHandler }; // class SimpleHandler
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if(argc == 1) if(argc == 1)
{ {
std::cout << "Usage : " << argv[0] << " xmlfile ... " << std::endl; std::cout << "Usage : " << argv[0] << " xmlfile ... " << std::endl;
return 0; return 0;
} // if(argc == 0) } // if(argc == 0)
SAX2PYX handler; SAX2PYX handler;
for(int i = 1; i < argc; ++i) for(int i = 1; i < argc; ++i)
{ {
try try
{ {
SAX::XMLReader<std::string> myParser; SAX::XMLReader<std::string> myParser;
myParser.setContentHandler(handler); myParser.setContentHandler(handler);
myParser.setErrorHandler(handler); myParser.setErrorHandler(handler);
handler.setParser(myParser);
SAX::InputSource is(argv[i]); SAX::InputSource is(argv[i]);
myParser.parse(is); myParser.parse(is);
@ -61,9 +65,9 @@ int main(int argc, char* argv[])
{ {
std::cerr << "Parse problem " << e.what() << std::endl; std::cerr << "Parse problem " << e.what() << std::endl;
} // catch } // catch
} // for ... } // for ...
return 0; return 0;
} // main } // main
@ -79,6 +83,11 @@ void SAX2PYX::startElement(const std::string&, const std::string& localName,
<< std::endl; << std::endl;
} // for ... } // for ...
std::cerr << " "
<< parser_->getLineNumber()
<< ","
<< parser_->getColumnNumber()
<< std::endl;
} // startElement } // startElement
void SAX2PYX::endElement(const std::string&, const std::string& localName, void SAX2PYX::endElement(const std::string&, const std::string& localName,