00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "load_xml.h"
00016
00017
00018 #include <xercesc/util/PlatformUtils.hpp>
00019 #include <xercesc/sax2/SAX2XMLReader.hpp>
00020 #include <xercesc/sax2/XMLReaderFactory.hpp>
00021 #include <xercesc/sax2/DefaultHandler.hpp>
00022 #include <xercesc/util/XMLString.hpp>
00023
00024 #include "load_xml_handle.h"
00025
00026 #ifdef __cplusplus
00027 extern "C" {
00028 int loadall_xml(char *file);
00029 }
00030 #else
00031
00032 #endif
00033
00034
00035 XERCES_CPP_NAMESPACE_USE
00036
00037
00038
00039
00040
00041
00042
00043 int loadall_xml(char *filename){
00044 if(filename == NULL)
00045 return 0;
00046 try{
00047 XMLPlatformUtils::Initialize();
00048 } catch(const XMLException& ){
00049 output_error("Load_XML: Xerces Initialization failed.");
00050 output_debug(" * something really spectacularly nasty happened inside Xerces and outside our control.");
00051 return 0;
00052 }
00053
00054 SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
00055
00056
00057
00058 gld_loadHndl *defaultHandler = new gld_loadHndl();
00059 parser->setContentHandler(defaultHandler);
00060 parser->setErrorHandler(defaultHandler);
00061
00062 try {
00063 parser->parse(filename);
00064 } catch (const XMLException& toCatch){
00065 char* message = XMLString::transcode(toCatch.getMessage());
00066 output_error("Load_XML: XMLException from Xerces: %s", message);
00067 XMLString::release(&message);
00068 return 0;
00069 } catch (const SAXParseException& toCatch){
00070 char* message = XMLString::transcode(toCatch.getMessage());
00071 output_error("Load_XML: SAXParseException from Xerces: %s", message);
00072 XMLString::release(&message);
00073 return 0;
00074 } catch (...) {
00075 output_error("Load_XML: unexpected exception from Xerces.");
00076 return 0;
00077 }
00078 if(!defaultHandler->did_load()){
00079 output_error("Load_XML: loading failed.");
00080 return 0;
00081 }
00082 delete parser;
00083 delete defaultHandler;
00084 return 1;
00085 }
00086
00087