#pragma hdrstop #ifdef __BORLANDC__ #include #endif #pragma warning(disable:4786) #include "SimpleHandler.h" #include #include #include SAX::basic_XMLReader* parserFactory(std::string name) { #ifdef USE_EXPAT if(name == "expat") return new SAX::expat_wrapper; #endif #ifdef USE_GARDEN if(name == "garden") return new SAX::Garden; #endif #ifdef USE_MSXML if(name == "msxml") return new SAX::msxml2_wrapper; #endif #ifdef USE_LIBXML2 if(name == "libxml") return new SAX::libxml2_wrapper; #endif #ifdef USE_XERCES if(name == "xerces") return new SAX::xerces_wrapper; #endif std::cout << "unknown parser -> " << name << std::endl; exit(0); } //////////////////////////////////////////////// int main(int argc, char* argv[]) { if(argc < 3) { std::cout << "Usage : " << argv[0] << " parser_name xmlfile ... " << std::endl; return 0; } // if(argc == 0) SimpleHandler myHandler; SAX::FeatureNames fNames; SAX::PropertyNames pNames; for(int i = 2; i < argc; ++i) { std::auto_ptr > parser(parserFactory(argv[1])); try { parser->setFeature(fNames.external_general, true); parser->setFeature(fNames.validation, true); parser->setFeature(fNames.namespaces, true); parser->setFeature(fNames.namespace_prefixes, true); } catch(SAX::SAXException& e) { std::cerr << e.what() << std::endl; } parser->setContentHandler(myHandler); parser->setDTDHandler(myHandler); parser->setErrorHandler(myHandler); parser->setEntityResolver(myHandler); try { parser->setProperty(pNames.declHandler, static_cast(myHandler)); parser->setProperty(pNames.lexicalHandler, static_cast(myHandler)); } catch(SAX::SAXException& e) { std::cout << e.what() << std::endl; } // catch std::string file(argv[i]); if(file != "-") parser->parse(file); else { SAX::InputSource is; is.setSystemId("stdin"); is.setByteStream(std::cin); parser->parse(is); } // } return 0; } // main // end of file