xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bob Jamison <rjami...@lincom-asg.com>
Subject Re: Using Xalan with Apache
Date Thu, 04 Jan 2001 18:18:39 GMT
?? wrote:

> Current version of Xalan-C++ was implemented using C++.
> Thus, it is impossible to use it in Apache web server, I think.
> Maybe there might be someway to port the C++ version to C,
> but I think it would be so painful job.

It's really no problem.  Just make a few C wrapper functions
around the C++ calls in a .cpp file, and have the
corresponding .h prototype file be C-only.



Here is a Xerces example, Xalan should work the same.
Have a file called parser.cpp:


#include "parser.h"

class MySaxHandler : public DefaultHandler
{
  //overload the methods
}

int parseMyFile(char *fileName,struct SomethingToBeFilled *dest)
{
  try
   {
   XMLPlatformUtils::Initialize();
   SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
   MySaxHandler handler;
   handler.setOutputStruct(dest);
   parser->setContentHandler(&handler);
   parser->setErrorHandler(&handler);
   parser->parse(fileName);
   XMLPlatformUtils::Terminate();
   }
  catch (const XMLException &e)
   {
   //error messages
   return 0;
   }
  return 1;
}



in parser.h:

#ifdef __cplusplus
extern "C" {
#endif __cplusplus
int parseMyFile(char *fileName,struct SomeThingToBeFilled *dest);
#ifdef __cplusplus
}
#endif __cplusplus




The 'extern C'  declaration will prevent the
function name from being mangled, so it can
be called from a module's C code.




Bob Jamison
LinCom Corp







Mime
View raw message