arabica/examples/XSLT/mangle.cpp

61 lines
1.5 KiB
C++
Raw Normal View History

#ifdef _MSC_VER
2012-11-21 07:59:40 +01:00
#pragma warning(disable : 4250 4244)
#endif
2007-07-19 18:58:57 +02:00
#include <iostream>
#include <string>
#include <sstream>
#include <XSLT/XSLT.hpp>
2012-11-21 07:59:40 +01:00
Arabica::DOM::Document<std::string> buildDOM(const std::string & xml);
2007-07-19 18:58:57 +02:00
int main(int argc, const char* argv[])
{
if(argc != 3)
{
std::cout << "mangle is an (in-development) XSLT processor\n"
<< argv[0] << " xmlfile xsltfile" << std::endl;
return 0;
} // if ...
try
2007-07-19 18:58:57 +02:00
{
2012-11-21 07:59:40 +01:00
Arabica::SAX::InputSource<std::string> source(argv[2]);
Arabica::XSLT::StylesheetCompiler<std::string> compiler;
std::unique_ptr<Arabica::XSLT::Stylesheet<std::string> > stylesheet = compiler.compile(source);
2007-07-19 18:58:57 +02:00
if(stylesheet.get() == 0)
{
std::cerr << "Couldn't compile stylesheet: " << compiler.error() << std::endl;
return -1;
} // if ...
stylesheet->set_error_output(std::cerr);
2007-07-19 18:58:57 +02:00
2012-11-21 07:59:40 +01:00
Arabica::DOM::Document<std::string> document = buildDOM(argv[1]);
2007-07-19 18:58:57 +02:00
if(document == 0)
{
std::cerr << "Could not parse XML source" << std::endl;
return 0;
} // if ...
stylesheet->execute(document);
}
catch(const std::runtime_error& ex)
{
std::cerr << ex.what() << std::endl;
} // catch
return 0;
} // main
2012-11-21 07:59:40 +01:00
Arabica::DOM::Document<std::string> buildDOM(const std::string & filename)
2007-07-19 18:58:57 +02:00
{
2012-11-21 07:59:40 +01:00
Arabica::SAX::InputSource<std::string> is(filename);
Arabica::SAX2DOM::Parser<std::string> parser;
2007-07-19 18:58:57 +02:00
parser.parse(is);
return parser.getDocument();
} // buildDOM