mirror of
https://github.com/jezhiggins/arabica
synced 2025-01-14 08:01:49 +01:00
use default parser
This commit is contained in:
parent
09d0ca7c89
commit
377fd7ab97
1 changed files with 17 additions and 40 deletions
|
@ -11,38 +11,12 @@
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
SAX::basic_XMLReader<std::string>* parserFactory(std::string name)
|
||||
{
|
||||
#ifdef USE_EXPAT
|
||||
if(name == "expat")
|
||||
return new SAX::expat_wrapper<std::string>;
|
||||
#endif
|
||||
#ifdef USE_GARDEN
|
||||
if(name == "garden")
|
||||
return new SAX::Garden;
|
||||
#endif
|
||||
#ifdef USE_MSXML
|
||||
if(name == "msxml")
|
||||
return new SAX::msxml2_wrapper<std::string>;
|
||||
#endif
|
||||
#ifdef USE_LIBXML2
|
||||
if(name == "libxml")
|
||||
return new SAX::libxml2_wrapper<std::string>;
|
||||
#endif
|
||||
#ifdef USE_XERCES
|
||||
if(name == "xerces")
|
||||
return new SAX::xerces_wrapper<std::string>;
|
||||
#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;
|
||||
std::cout << "Usage : " << argv[0] << " xmlfile ... " << std::endl;
|
||||
return 0;
|
||||
} // if(argc == 0)
|
||||
|
||||
|
@ -52,29 +26,29 @@ int main(int argc, char* argv[])
|
|||
|
||||
for(int i = 2; i < argc; ++i)
|
||||
{
|
||||
std::auto_ptr<SAX::basic_XMLReader<std::string> > parser(parserFactory(argv[1]));
|
||||
SAX::XMLReader<std::string> parser;
|
||||
|
||||
try
|
||||
{
|
||||
parser->setFeature(fNames.external_general, true);
|
||||
parser->setFeature(fNames.validation, true);
|
||||
parser->setFeature(fNames.namespaces, true);
|
||||
parser->setFeature(fNames.namespace_prefixes, true);
|
||||
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);
|
||||
parser.setContentHandler(myHandler);
|
||||
parser.setDTDHandler(myHandler);
|
||||
parser.setErrorHandler(myHandler);
|
||||
parser.setEntityResolver(myHandler);
|
||||
|
||||
try
|
||||
{
|
||||
parser->setProperty(pNames.declHandler, static_cast<SAX::DeclHandler&>(myHandler));
|
||||
parser->setProperty(pNames.lexicalHandler, static_cast<SAX::LexicalHandler&>(myHandler));
|
||||
parser.setProperty(pNames.declHandler, static_cast<SAX::DeclHandler&>(myHandler));
|
||||
parser.setProperty(pNames.lexicalHandler, static_cast<SAX::LexicalHandler&>(myHandler));
|
||||
}
|
||||
catch(SAX::SAXException& e)
|
||||
{
|
||||
|
@ -84,14 +58,17 @@ int main(int argc, char* argv[])
|
|||
std::string file(argv[i]);
|
||||
|
||||
if(file != "-")
|
||||
parser->parse(file);
|
||||
{
|
||||
SAX::InputSource is(file);
|
||||
parser.parse(is);
|
||||
}
|
||||
else
|
||||
{
|
||||
SAX::InputSource is;
|
||||
is.setSystemId("stdin");
|
||||
is.setByteStream(std::cin);
|
||||
|
||||
parser->parse(is);
|
||||
parser.parse(is);
|
||||
} //
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue