xerces/xalan exception

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::eek: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::DOMException;

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::DOMParserType 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;
}
 
J

Jo

Jo said:
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::eek: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::DOMException;

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::DOMParserType 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;
}
If the XercesParserLiaison is allocated dynamically everything runs fine...
Does anybody know what's the catch ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top