25 #ifndef XML_PARSER20091211H 26 #define XML_PARSER20091211H 34 #include <xercesc/sax2/DefaultHandler.hpp> 35 #include <xercesc/sax2/SAX2XMLReader.hpp> 36 #include <xercesc/sax2/XMLReaderFactory.hpp> 37 #include <xercesc/util/PlatformUtils.hpp> 39 #include "message_schema.xsd.h" 40 #include "xerces_strings.h" 59 XMLParser(xercesc::DefaultHandler& content, xercesc::DefaultHandler& error)
60 : content_(content), error_(error)
64 bool parse(
const std::string& file)
68 std::auto_ptr<xercesc::SAX2XMLReader> parser(xercesc::XMLReaderFactory::createXMLReader());
71 const std::string schema =
"/tmp/dccl_message_schema.xsd";
73 fout.open(schema.c_str());
74 for (
unsigned i = 0; i < message_schema_xsd_len; ++i) fout << message_schema_xsd[i];
77 const XMLCh* xs_schema = fromNative(schema.c_str());
78 const XMLCh*
const schema_location = xs_schema;
79 parser->setFeature(xercesc::XMLUni::fgSAX2CoreValidation,
true);
80 parser->setProperty(xercesc::XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
81 (
void*)schema_location);
83 parser->setContentHandler(&content_);
84 parser->setErrorHandler(&error_);
87 parser->parse(file.c_str());
93 xercesc::DefaultHandler& content_;
94 xercesc::DefaultHandler& error_;