J
Jo
Hello,
What am I doing wrong ? I always end up with an exception regardless
of the provided XML/XSLT (although to ensure the correctness of
the provide input files I've used the ones which comes with the
xalan samples). Is it a memory mishandling error ?
I'm using Xerces 2.4 C++ / Xalan 1.7 C++ and VC6 to compile
the code :
#include <iostream>
#include <xercesc/framework/LocalFileInputSource.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xalanc/XercesParserLiaison/XercesParserLiaison.hpp>
#include <xalanc/XercesParserLiaison/XercesDOMSupport.hpp>
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
#include <xalanc/XalanTransformer/XercesDOMWrapperParsedSource.hpp>
using std::cout;
using std::cerr;
using std::endl;
using std::ifstream;
using std:fstream;
using XERCES_CPP_NAMESPACE::XMLPlatformUtils;
using XERCES_CPP_NAMESPACE::LocalFileInputSource;
using XERCES_CPP_NAMESPACE::XMLString;
using XERCES_CPP_NAMESPACE::XMLException;
using XERCES_CPP_NAMESPACE:OMException;
using XALAN_CPP_NAMESPACE::XalanCompiledStylesheet;
using XALAN_CPP_NAMESPACE::XalanDOMString;
using XALAN_CPP_NAMESPACE::XalanTransformer;
using XALAN_CPP_NAMESPACE::XSLTInputSource;
using XALAN_CPP_NAMESPACE::XSLTResultTarget;
using XALAN_CPP_NAMESPACE::XercesParserLiaison;
using XALAN_CPP_NAMESPACE::XercesDOMSupport;
using XALAN_CPP_NAMESPACE::XercesDOMWrapperParsedSource;
int main(void){
try{
// Call the static initializer for Xerces.
XMLPlatformUtils::Initialize();
// Initialize Xalan.
XalanTransformer::initialize();
try{
// Create a XalanTransformer.
XalanTransformer theTransformer;
const XSLTInputSource theStylesheetInputSource("foo.xsl");
// Compile the stylesheet and re-use it...
const XalanCompiledStylesheet* theStylesheet = 0;
if (theTransformer.compileStylesheet(theStylesheetInputSource,
theStylesheet) != 0)
cerr<<"An error occurred compiling the stylesheet:
"<<theTransformer.getLastError()<<endl;
else{
XalanDOMString theURI("foo.xml");
XSLTResultTarget theResultTarget(cout);
LocalFileInputSource theXMLInputSource(theURI.c_str());
XercesParserLiaison:OMParserType theParser;
theParser.parse(theXMLInputSource);
XercesParserLiaison theParserLiaison;
XercesDOMSupport theDOMSupport;
const XercesDOMWrapperParsedSource theWrapper(theParser.getDocument(),
theParserLiaison, theDOMSupport, theURI);
theTransformer.transform(theWrapper, theStylesheet, theResultTarget);
}
}
catch(...){
cerr << "Exception" << endl;
}
// Terminate Xalan...
XalanTransformer::terminate();
// Terminate Xerces...
XMLPlatformUtils::Terminate();
// Clean up the ICU, if it's integrated...
XalanTransformer::ICUCleanUp();
}
catch(...){
cerr << "Initialization failed!" << endl;
}
return 0;
}
What am I doing wrong ? I always end up with an exception regardless
of the provided XML/XSLT (although to ensure the correctness of
the provide input files I've used the ones which comes with the
xalan samples). Is it a memory mishandling error ?
I'm using Xerces 2.4 C++ / Xalan 1.7 C++ and VC6 to compile
the code :
#include <iostream>
#include <xercesc/framework/LocalFileInputSource.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLString.hpp>
#include <xalanc/XercesParserLiaison/XercesParserLiaison.hpp>
#include <xalanc/XercesParserLiaison/XercesDOMSupport.hpp>
#include <xalanc/XalanTransformer/XalanTransformer.hpp>
#include <xalanc/XalanTransformer/XercesDOMWrapperParsedSource.hpp>
using std::cout;
using std::cerr;
using std::endl;
using std::ifstream;
using std:fstream;
using XERCES_CPP_NAMESPACE::XMLPlatformUtils;
using XERCES_CPP_NAMESPACE::LocalFileInputSource;
using XERCES_CPP_NAMESPACE::XMLString;
using XERCES_CPP_NAMESPACE::XMLException;
using XERCES_CPP_NAMESPACE:OMException;
using XALAN_CPP_NAMESPACE::XalanCompiledStylesheet;
using XALAN_CPP_NAMESPACE::XalanDOMString;
using XALAN_CPP_NAMESPACE::XalanTransformer;
using XALAN_CPP_NAMESPACE::XSLTInputSource;
using XALAN_CPP_NAMESPACE::XSLTResultTarget;
using XALAN_CPP_NAMESPACE::XercesParserLiaison;
using XALAN_CPP_NAMESPACE::XercesDOMSupport;
using XALAN_CPP_NAMESPACE::XercesDOMWrapperParsedSource;
int main(void){
try{
// Call the static initializer for Xerces.
XMLPlatformUtils::Initialize();
// Initialize Xalan.
XalanTransformer::initialize();
try{
// Create a XalanTransformer.
XalanTransformer theTransformer;
const XSLTInputSource theStylesheetInputSource("foo.xsl");
// Compile the stylesheet and re-use it...
const XalanCompiledStylesheet* theStylesheet = 0;
if (theTransformer.compileStylesheet(theStylesheetInputSource,
theStylesheet) != 0)
cerr<<"An error occurred compiling the stylesheet:
"<<theTransformer.getLastError()<<endl;
else{
XalanDOMString theURI("foo.xml");
XSLTResultTarget theResultTarget(cout);
LocalFileInputSource theXMLInputSource(theURI.c_str());
XercesParserLiaison:OMParserType theParser;
theParser.parse(theXMLInputSource);
XercesParserLiaison theParserLiaison;
XercesDOMSupport theDOMSupport;
const XercesDOMWrapperParsedSource theWrapper(theParser.getDocument(),
theParserLiaison, theDOMSupport, theURI);
theTransformer.transform(theWrapper, theStylesheet, theResultTarget);
}
}
catch(...){
cerr << "Exception" << endl;
}
// Terminate Xalan...
XalanTransformer::terminate();
// Terminate Xerces...
XMLPlatformUtils::Terminate();
// Clean up the ICU, if it's integrated...
XalanTransformer::ICUCleanUp();
}
catch(...){
cerr << "Initialization failed!" << endl;
}
return 0;
}