xerces/xalan exception

Discussion in 'XML' started by Jo, Jun 13, 2004.

  1. Jo

    Jo Guest

    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;
    }
    Jo, Jun 13, 2004
    #1
    1. Advertising

  2. Jo

    Jo Guest

    Jo wrote:
    > 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 ?
    Jo, Jun 15, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sp

    xerces and xalan

    sp, Sep 18, 2004, in forum: Java
    Replies:
    2
    Views:
    6,640
    Mike Schilling
    Sep 18, 2004
  2. Mark F
    Replies:
    0
    Views:
    443
    Mark F
    Mar 7, 2005
  3. Alex

    xalan and Xerces?

    Alex, Oct 24, 2003, in forum: XML
    Replies:
    1
    Views:
    444
    Bob Foster
    Oct 25, 2003
  4. Volker Jordan

    Xpath apache xerces/xalan dom3

    Volker Jordan, Jan 22, 2004, in forum: XML
    Replies:
    0
    Views:
    530
    Volker Jordan
    Jan 22, 2004
  5. cvissy
    Replies:
    0
    Views:
    592
    cvissy
    Nov 16, 2004
Loading...

Share This Page