arabica/examples/SAX/wrapper.cpp

70 lines
1.5 KiB
C++
Raw Normal View History

#ifdef _MSC_VER
2002-06-21 13:16:28 +02:00
#pragma warning(disable:4786)
#endif
2002-06-21 13:16:28 +02:00
2007-09-05 00:55:47 +02:00
#include "SimpleHandler.hpp"
#include <SAX/InputSource.hpp>
#include <SAX/helpers/FeatureNames.hpp>
#include <SAX/helpers/PropertyNames.hpp>
2002-06-21 13:16:28 +02:00
#include <iostream>
#include <sstream>
////////////////////////////////////////////////
int main(int argc, char* argv[])
{
if(argc < 2)
2002-06-21 13:16:28 +02:00
{
2002-09-02 12:36:21 +02:00
std::cout << "Usage : " << argv[0] << " xmlfile ... " << std::endl;
2002-06-21 13:16:28 +02:00
return 0;
} // if(argc == 0)
SimpleHandler myHandler;
2002-06-21 13:16:28 +02:00
SAX::FeatureNames<std::string> fNames;
SAX::PropertyNames<std::string> pNames;
for(int i = 1; i < argc; ++i)
2002-06-21 13:16:28 +02:00
{
2002-09-02 12:36:21 +02:00
SAX::XMLReader<std::string> parser;
2002-06-21 13:16:28 +02:00
try
{
2002-09-02 12:36:21 +02:00
parser.setFeature(fNames.external_general, true);
parser.setFeature(fNames.validation, true);
parser.setFeature(fNames.namespaces, true);
parser.setFeature(fNames.namespace_prefixes, true);
2002-06-21 13:16:28 +02:00
}
catch(SAX::SAXException& e)
{
std::cerr << e.what() << std::endl;
}
2002-09-02 12:36:21 +02:00
parser.setContentHandler(myHandler);
parser.setDTDHandler(myHandler);
parser.setErrorHandler(myHandler);
parser.setEntityResolver(myHandler);
2007-07-19 18:58:57 +02:00
parser.setDeclHandler(myHandler);
parser.setLexicalHandler(myHandler);
2002-06-21 13:16:28 +02:00
std::string file(argv[i]);
if(file != "-")
2002-09-02 12:36:21 +02:00
{
SAX::InputSource is(file);
parser.parse(is);
}
2002-06-21 13:16:28 +02:00
else
{
SAX::InputSource is;
is.setSystemId("stdin");
is.setByteStream(std::cin);
2002-09-02 12:36:21 +02:00
parser.parse(is);
2002-06-21 13:16:28 +02:00
} //
}
return 0;
} // main
// end of file