mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-30 08:38:15 +01:00
Used DefaultHandler::fatalError and catch thrown exception
This commit is contained in:
parent
8e9d4d6ea7
commit
9bff72c42a
1 changed files with 19 additions and 19 deletions
|
@ -29,9 +29,8 @@ class SAX2PYX : public SAX::DefaultHandler
|
||||||
virtual void characters(const std::string& ch);
|
virtual void characters(const std::string& ch);
|
||||||
virtual void processingInstruction(const std::string& target, const std::string& data);
|
virtual void processingInstruction(const std::string& target, const std::string& data);
|
||||||
|
|
||||||
virtual void warning(const SAX::SAXException& e) { fatalError(e); }
|
virtual void warning(const SAX::SAXParseException& e) { fatalError(e); }
|
||||||
virtual void error(const SAX::SAXException& e) { fatalError(e); }
|
virtual void error(const SAX::SAXParseException& e) { fatalError(e); }
|
||||||
virtual void fatalError(const SAX::SAXException& e);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string escape(const std::string& str) const;
|
std::string escape(const std::string& str) const;
|
||||||
|
@ -49,20 +48,27 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
for(int i = 1; i < argc; ++i)
|
for(int i = 1; i < argc; ++i)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
SAX::XMLReader<std::string> myParser;
|
SAX::XMLReader<std::string> myParser;
|
||||||
myParser.setContentHandler(handler);
|
myParser.setContentHandler(handler);
|
||||||
myParser.setErrorHandler(handler);
|
myParser.setErrorHandler(handler);
|
||||||
|
|
||||||
SAX::InputSource is(argv[i]);
|
SAX::InputSource is(argv[i]);
|
||||||
myParser.parse(is);
|
myParser.parse(is);
|
||||||
}
|
} // try
|
||||||
|
catch(std::runtime_error& e)
|
||||||
|
{
|
||||||
|
std::cerr << "Parse problem " << e.what() << std::endl;
|
||||||
|
} // catch
|
||||||
|
} // for ...
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} // main
|
} // main
|
||||||
|
|
||||||
|
|
||||||
void SAX2PYX::startElement(const std::string& namespaceURI, const std::string& localName,
|
void SAX2PYX::startElement(const std::string&, const std::string& localName,
|
||||||
const std::string& qName, const SAX::Attributes& atts)
|
const std::string&, const SAX::Attributes& atts)
|
||||||
{
|
{
|
||||||
std::cout << '(' << localName << std::endl;
|
std::cout << '(' << localName << std::endl;
|
||||||
|
|
||||||
|
@ -75,8 +81,8 @@ void SAX2PYX::startElement(const std::string& namespaceURI, const std::string& l
|
||||||
|
|
||||||
} // startElement
|
} // startElement
|
||||||
|
|
||||||
void SAX2PYX::endElement(const std::string& namespaceURI, const std::string& localName,
|
void SAX2PYX::endElement(const std::string&, const std::string& localName,
|
||||||
const std::string& qName)
|
const std::string&)
|
||||||
{
|
{
|
||||||
std::cout << ')' << localName << std::endl;
|
std::cout << ')' << localName << std::endl;
|
||||||
} // endElement
|
} // endElement
|
||||||
|
@ -104,10 +110,4 @@ std::string SAX2PYX::escape(const std::string& str) const
|
||||||
return estr;
|
return estr;
|
||||||
} // escape
|
} // escape
|
||||||
|
|
||||||
void SAX2PYX::fatalError(const SAX::SAXException& e)
|
|
||||||
{
|
|
||||||
std::cerr << "Parse problem " << e.what() << std::endl;
|
|
||||||
exit(0);
|
|
||||||
} // fatalError
|
|
||||||
|
|
||||||
// end of file
|
// end of file
|
||||||
|
|
Loading…
Add table
Reference in a new issue