arabica/examples/XSLT/mangle.cpp

81 lines
2.1 KiB
C++
Raw Normal View History

#ifdef _MSC_VER
2007-07-19 18:58:57 +02:00
#pragma warning(disable : 4250)
#endif
2007-07-19 18:58:57 +02:00
#include <iostream>
#include <string>
#include <sstream>
2007-09-05 00:55:47 +02:00
#include <SAX/InputSource.hpp>
#include <DOM/SAX2DOM/SAX2DOM.hpp>
2007-11-19 23:11:05 +01:00
#include <DOM/io/Stream.hpp>
2007-07-19 18:58:57 +02:00
#include <XSLT/XSLT.hpp>
Arabica::DOM::Document<std::wstring> buildDOM(const std::wstring& xml);
typedef Arabica::default_string_adaptor<std::wstring> adaptor;
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 ...
Arabica::XSLT::StylesheetCompiler<std::wstring> compiler;
std::wostringstream errors;
2007-07-19 18:58:57 +02:00
try
{
Arabica::SAX::InputSource<std::wstring> source(adaptor::construct_from_utf8(argv[2]));
std::auto_ptr<Arabica::XSLT::Stylesheet<std::wstring> > 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(errors);
Arabica::DOM::Document<std::wstring> document = buildDOM(adaptor::construct_from_utf8(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 ...
2008-09-16 09:31:30 +02:00
//document.normalize();
2007-07-19 18:58:57 +02:00
stylesheet->execute(document);
2007-11-19 23:11:05 +01:00
2010-01-09 22:25:52 +01:00
/*
std::cout << "\n==============" << std::endl;
2007-11-19 23:11:05 +01:00
Arabica::XSLT::DOMSink output;
stylesheet->set_output(output);
stylesheet->execute(document);
Arabica::DOM::Node<std::wstring> node = output.node();
2007-11-19 23:11:05 +01:00
std::cout << node << std::endl;
2010-01-09 22:25:52 +01:00
*/
2007-07-19 18:58:57 +02:00
}
catch(const std::runtime_error& ex)
{
std::cerr << ex.what() << std::endl;
} // catch
std::wcerr << "\n\n" << errors.str() << std::endl;
2007-07-19 18:58:57 +02:00
return 0;
} // main
Arabica::DOM::Document<std::wstring> buildDOM(const std::wstring& filename)
2007-07-19 18:58:57 +02:00
{
Arabica::SAX::InputSource<std::wstring> is(filename);
Arabica::SAX2DOM::Parser<std::wstring> parser;
2007-07-19 18:58:57 +02:00
parser.parse(is);
return parser.getDocument();
} // buildDOM