本文整理汇总了C++中SAX2XMLReader::setContentHandler方法的典型用法代码示例。如果您正苦于以下问题:C++ SAX2XMLReader::setContentHandler方法的具体用法?C++ SAX2XMLReader::setContentHandler怎么用?C++ SAX2XMLReader::setContentHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SAX2XMLReader
的用法示例。
在下文中一共展示了SAX2XMLReader::setContentHandler方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
// QApplication a(argc, argv);
// testSclParser w;
// w.show();
int seconds = time((time_t*)NULL);
CScl* pScl= new CScl;
XMLPlatformUtils::Initialize();
MemoryManager* fgMemoryManager = XMLPlatformUtils::fgMemoryManager;
//XMLGrammarPool* pGrammarPool = new XMLGrammarPoolImpl(XMLPlatformUtils::fgMemoryManager);
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader(XMLPlatformUtils::fgMemoryManager);
SclSAX2Handler*myContentHandler = new SclSAX2Handler(pScl,1);
parser->setContentHandler((SclSAX2Handler*)myContentHandler);
///m_pSclFacty->LoadSclFile();
parser->parse("yab.scd");//½âÎöxmlÎļþ
int seconds2 = time((time_t*)NULL);
int SpendTime = seconds2-seconds;
printf("Reading SCD...%d have elapsed",SpendTime);
char* strIP = pScl->GetIEDIP("CL1101A","MMS_A");
char* strManufacture = pScl->GetManufacturer("CL1101A");
printf("CL1101A ip = %s\n",strIP);
printf("CL1101A manufacture = %s\n",strManufacture);
return 0;
// return a.exec();
}
示例2: isValid
bool XMLValidator::isValid(const String & filename, const String & schema, std::ostream & os)
{
filename_ = filename;
os_ = &os;
//try to open file
if (!File::exists(filename))
{
throw Exception::FileNotFound(__FILE__, __LINE__, __PRETTY_FUNCTION__, filename);
}
// initialize parser
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException & toCatch)
{
throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, "", String("Error during initialization: ") + Internal::StringManager().convert(toCatch.getMessage()));
}
SAX2XMLReader * parser = XMLReaderFactory::createXMLReader();
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
parser->setFeature(XMLUni::fgXercesDynamic, false);
parser->setFeature(XMLUni::fgXercesSchema, true);
parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
//set this class as error handler
parser->setErrorHandler(this);
parser->setContentHandler(NULL);
parser->setEntityResolver(NULL);
//load schema
LocalFileInputSource schema_file(Internal::StringManager().convert(schema));
parser->loadGrammar(schema_file, Grammar::SchemaGrammarType, true);
parser->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, true);
// try to parse file
LocalFileInputSource source(Internal::StringManager().convert(filename.c_str()));
try
{
parser->parse(source);
delete(parser);
}
catch (...)
{
/// nothing to do here
}
return valid_;
}
示例3: handler
bool
O2Profile::
ImportFromXML(const wchar_t *filename, const char *in, uint len)
{
bool ret = false;
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
O2Profile_SAX2Handler handler(Logger, this);
parser->setContentHandler(&handler);
parser->setErrorHandler(&handler);
Lock();
{
try {
if (filename) {
#ifdef _MSC_VER /** VC++ */
LocalFileInputSource source(filename);
#else /** GCC/Clang */
LocalFileInputSource source(reinterpret_cast<const XMLCh*>(filename));
#endif
parser->parse(source);
}
else {
MemBufInputSource source((const XMLByte*)in, len, "");
parser->parse(source);
}
ret = true;
}
catch (const OutOfMemoryException &e) {
if (Logger) {
Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
L"SAX2: Out of Memory: %s", e.getMessage());
}
}
catch (const XMLException &e) {
if (Logger) {
Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
L"SAX2: Exception: %s", e.getMessage());
}
}
catch (...) {
if (Logger) {
Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
L"SAX2: Unexpected exception during parsing.");
}
}
}
Unlock();
delete parser;
return (ret);
}
示例4: loadall_xml
// Other include files, declarations, and non-Xerces-C++ initializations.
XERCES_CPP_NAMESPACE_USE
/*int main(int argc, char** argv){
char* xmlFile = "well-formatted-new.xml";
//char *xmlFile = "GridLABD_Multi_Example.xml";
return loadall_xml(xmlFile);
}*/
int loadall_xml(char *filename){
if(filename == NULL)
return 0;
try{
XMLPlatformUtils::Initialize();
} catch(const XMLException& /*toCatch*/){
output_error("Load_XML: Xerces Initialization failed.");
output_debug(" * something really spectacularly nasty happened inside Xerces and outside our control.");
return 0;
}
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
parser->setFeature(XMLUni::fgXercesDynamic, true);
//parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
//parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); // optional
gld_loadHndl *defaultHandler = new gld_loadHndl();
parser->setContentHandler(defaultHandler);
parser->setErrorHandler(defaultHandler);
try {
parser->parse(filename);
} catch (const XMLException& toCatch){
char* message = XMLString::transcode(toCatch.getMessage());
output_error("Load_XML: XMLException from Xerces: %s", message);
XMLString::release(&message);
return 0;
} catch (const SAXParseException& toCatch){
char* message = XMLString::transcode(toCatch.getMessage());
output_error("Load_XML: SAXParseException from Xerces: %s", message);
XMLString::release(&message);
return 0;
} catch (...) {
output_error("Load_XML: unexpected exception from Xerces.");
return 0;
}
if(!defaultHandler->did_load()){
output_error("Load_XML: loading failed.");
return 0;
}
delete parser;
delete defaultHandler;
return 1;
}
示例5: ReadFile
int GpXmlReader::ReadFile(string& filename, GpCodeModel* model)
{
DEBOUT("GpXmlReader::ReadFile()");
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); // optional
if (!model)
{
throw std::invalid_argument("Null pointer passed to GpXmlReader::ReadFile()");
}
GpXmlSAXContentHandler* handler = new GpXmlSAXContentHandler(model);
parser->setContentHandler(handler);
parser->setErrorHandler(handler);
try
{
parser->parse(filename.c_str() );
}
catch (const XMLException& toCatch)
{
char* message = XMLString::transcode(toCatch.getMessage() );
cout << "Exception message is: \n"
<< message << "\n";
XMLString::release(&message);
return -1;
}
catch (const SAXParseException& toCatch)
{
char* message = XMLString::transcode(toCatch.getMessage() );
cout << "Exception message is: \n"
<< message << "\n";
XMLString::release(&message);
return -1;
}
catch (const std::exception& except)
{
cout << except.what() << '\n';
return -1;
}
catch (...)
{
cout << "Unexpected Exception \n";
return -1;
}
delete parser;
delete handler;
return 0;
}
示例6: SHandler
/*
=======================================================================================================================
* TODO:
=======================================================================================================================
*/
void cLoadXML::Sax2ReadXML (const char* filename) {
/* create SAX2 parser and read the basic building block setting file */
SAX2XMLReader* parser;
/* create handler that will parse the XML elements */
SHandler* handler;
parser = XMLReaderFactory::createXMLReader ();
handler = new SHandler (recordNode, recordLink, nodeIndex, linkIndex);
parser->setContentHandler (handler);
parser->setErrorHandler (handler);
try
{
parser->parse (filename);
}
catch (const XMLException&toCatch) {
char* message;
message = XMLString::transcode (toCatch.getMessage ());
/*
* err << "Exception message is: \n" ;
* << message << "\n";
*/
XMLString::release (&message);
}
catch (const SAXParseException&toCatch) {
char* message;
message = XMLString::transcode (toCatch.getMessage ());
/*
* err << "Exception message is: \n" ;
* << message << "\n";
*/
XMLString::release (&message);
}
catch (...) {
/*
* err << "Unexpected Exception \n" ;
*/
}
delete parser;
delete handler;
XMLPlatformUtils::Terminate ();
}
示例7: getParser
static SAX2XMLReader* getParser(XMLGrammarPool* const theGramPool
, bool setHandler)
{
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader(theGramPool->getMemoryManager(), theGramPool);
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, doNamespaces);
parser->setFeature(XMLUni::fgXercesSchema, doSchema);
parser->setFeature(XMLUni::fgXercesSchemaFullChecking, schemaFullChecking);
parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, namespacePrefixes);
if (valScheme == SAX2XMLReader::Val_Auto)
{
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
parser->setFeature(XMLUni::fgXercesDynamic, true);
}
if (valScheme == SAX2XMLReader::Val_Never)
{
parser->setFeature(XMLUni::fgSAX2CoreValidation, false);
}
if (valScheme == SAX2XMLReader::Val_Always)
{
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
parser->setFeature(XMLUni::fgXercesDynamic, false);
}
if (setHandler)
{
parser->setContentHandler(handler);
parser->setErrorHandler(handler);
}
else
{
parser->setContentHandler(0);
parser->setErrorHandler(0);
}
return parser;
}
示例8: parseURL
//////////////////////////////////////////////////////////////////////////////
/// \brief 지정된 위치에 있는 파일 또는 웹 문서를 파싱한다.
///
/// \param pURL
//////////////////////////////////////////////////////////////////////////////
void XMLParser::parseURL(const char* pURL)
{
assert(pURL != NULL);
assert(m_pHandler != NULL);
// SAX 파서 오브젝트를 생성한다. 그리고 feature를 설정한다.
// SAX2에서 지원되는 feature는 다음과 같다.
//
// validation (default: true)
// namespaces (default: true)
// namespace-prefixes (default: false)
// validation/dynamic (default: false)
// reuse-grammar (default: false)
// schema (default: true)
// schema-full-checking (default: false)
// load-external-dtd (default: true)
// continue-after-fatal-error (default: false)
// validation-error-as-fatal (default: false)
//
// 자세한 사항은 다음 주소를 참고하기 바란다.
// http://xml.apache.org/xerces-c/program-sax2.html#SAX2Features
SAX2XMLReader* pParser = XMLReaderFactory::createXMLReader();
pParser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
pParser->setFeature(XMLUni::fgXercesSchema, true);
pParser->setFeature(XMLUni::fgXercesSchemaFullChecking, false);
pParser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, false);
pParser->setFeature(XMLUni::fgSAX2CoreValidation, true);
pParser->setFeature(XMLUni::fgXercesDynamic, true);
pParser->setContentHandler(m_pHandler);
pParser->setErrorHandler(m_pHandler);
try
{
pParser->parse(pURL);
}
catch (const XMLException& e)
{
XMLUtil::filelog(
"\nError during parsing! Exception Message: \n%s\n",
XMLUtil::WideCharToString(e.getMessage()).c_str());
}
catch (...)
{
XMLUtil::filelog(
"Unexpected exception during parsing!\n");
}
delete pParser;
}
示例9: main
int main (int argc, char* args[]) {
try {
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Error during initialization! :\n";
cout << "Exception message is: \n"
<< message << "\n";
XMLString::release(&message);
return 1;
}
StdInInputSource lStdInStream;
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); // optional
XMLSerializer* defaultHandler = new XMLSerializer(wcout);
parser->setContentHandler(defaultHandler);
parser->setErrorHandler(defaultHandler);
try {
parser->parse(lStdInStream);
}
catch (const XMLException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Exception message is: \n"
<< message << "\n";
XMLString::release(&message);
return -1;
}
catch (const SAXParseException& toCatch) {
char* message = XMLString::transcode(toCatch.getMessage());
cout << "Exception message is: \n"
<< message << "\n";
XMLString::release(&message);
return -1;
}
catch (...) {
cout << "Unexpected Exception \n" ;
return -1;
}
delete parser;
delete defaultHandler;
return 0;
}
示例10:
XERCES_CPP_NAMESPACE::SAX2XMLReader* XercesParser::createReader(XERCES_CPP_NAMESPACE::DefaultHandler& handler)
{
XERCES_CPP_NAMESPACE_USE;
SAX2XMLReader* reader = XMLReaderFactory::createXMLReader();
// set basic settings we want from parser
reader->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
// set handlers
reader->setContentHandler(&handler);
reader->setErrorHandler(&handler);
return reader;
}
示例11: source
// ---------------------------------------------------------------------------
// LoadEx()
// 独自の情報を別ファイルから読む
// ---------------------------------------------------------------------------
bool
O2Boards::
LoadEx(void)
{
bool ret = false;
struct _stat st;
if (_wstat(exfilepath.c_str(), &st) == -1)
return false;
if (st.st_size == 0)
return false;
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
parser->setContentHandler(this);
parser->setErrorHandler(this);
try {
#ifdef _MSC_VER
LocalFileInputSource source(exfilepath.c_str());
#else
LocalFileInputSource source(reinterpret_cast<const XMLCh*>(exfilepath.c_str()));
#endif
parser->parse(source);
ret = true;
}
catch (const OutOfMemoryException &e) {
if (Logger) {
Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
L"SAX2: Out of Memory: %s", e.getMessage());
}
}
catch (const XMLException &e) {
if (Logger) {
Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
L"SAX2: Exception: %s", e.getMessage());
}
}
catch (...) {
if (Logger) {
Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
L"SAX2: Unexpected exception during parsing.");
}
}
delete parser;
return (ret);
}
示例12: handler
size_t
O2IMDB::
ImportFromXML(const wchar_t *filename, const char *in, uint len)
{
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
O2IMDB_SAX2Handler handler(Logger, this);
parser->setContentHandler(&handler);
parser->setErrorHandler(&handler);
try {
if (filename) {
#ifdef _MSC_VER /** loose VC++ cast...*/
LocalFileInputSource source(filename);
#else /** use reinterpret_cast for GCC */
LocalFileInputSource source(reinterpret_cast<const XMLCh*>(filename));
#endif
parser->parse(source);
}
else {
MemBufInputSource source((const XMLByte*)in, len, "");
parser->parse(source);
}
}
catch (const OutOfMemoryException &e) {
if (Logger) {
Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
L"SAX2: Out of Memory: %s", e.getMessage());
}
}
catch (const XMLException &e) {
if (Logger) {
Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
L"SAX2: Exception: %s", e.getMessage());
}
}
catch (...) {
if (Logger) {
Logger->AddLog(O2LT_ERROR, MODULE, 0, 0,
L"SAX2: Unexpected exception during parsing.");
}
}
delete parser;
return (handler.GetParseNum());
}
示例13: handler
//____________________________________________________________________________
void X2DB::parse(request_rec *r, my_server_config *config, const char *buf,
apr_size_t len)
{
try {
XMLPlatformUtils::Initialize();
} catch (const XMLException &x) {
XERCES_STD_QUALIFIER cout << "Error during initialization! :\n"
<< XMLString::transcode(x.getMessage()) << XERCES_STD_QUALIFIER endl;
return;
}
SAX2XMLReader *parser = XMLReaderFactory::createXMLReader();
parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
parser->setFeature(XMLUni::fgXercesDynamic, true);
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
parser->setFeature(XMLUni::fgXercesSchema, true);
parser->setFeature(XMLUni::fgXercesSchemaFullChecking, false);
parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, false);
int errorCode = 0;
try {
X2DB handler(r, config);
parser->setContentHandler(&handler);
parser->setErrorHandler(&handler);
ap_rputs("<result>", r);
parser->parse(MemBufInputSource(reinterpret_cast<XMLByte *>(const_cast<char *>(buf)), len, "HTTP"));
ap_rprintf(r, "<parse-errors count=\"%d\"/>", parser->getErrorCount());
ap_rputs("</result>", r);
} catch (const OutOfMemoryException &) {
XERCES_STD_QUALIFIER cout << "OutOfMemoryException" << XERCES_STD_QUALIFIER endl;
errorCode = 5;
} catch (const XMLException &x) {
XERCES_STD_QUALIFIER cout << "\nAn error occurred\n Error: "
<< XMLString::transcode(x.getMessage())
<< "\n" << XERCES_STD_QUALIFIER endl;
errorCode = 4;
}
if (errorCode) {
XMLPlatformUtils::Terminate();
return;
}
delete parser;
XMLPlatformUtils::Terminate();
return;
}
示例14: handler
uint64
O2IPFilter::
ImportFromXML(const wchar_t *filename, const char *in, uint len)
{
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
O2IPFilter_SAX2Handler handler(name.c_str(), Logger, this);
parser->setContentHandler(&handler);
parser->setErrorHandler(&handler);
try {
if (filename) {
LocalFileInputSource source(filename);
parser->parse(source);
}
else {
MemBufInputSource source((const XMLByte*)in, len, "");
parser->parse(source);
}
}
catch (const OutOfMemoryException &e) {
if (Logger) {
Logger->AddLog(O2LT_ERROR, name.c_str(), 0, 0,
L"SAX2: Out of Memory: %s", e.getMessage());
}
}
catch (const XMLException &e) {
if (Logger) {
Logger->AddLog(O2LT_ERROR, name.c_str(), 0, 0,
L"SAX2: Exception: %s", e.getMessage());
}
}
catch (...) {
if (Logger) {
Logger->AddLog(O2LT_ERROR, name.c_str(), 0, 0,
L"SAX2: Unexpected exception during parsing.");
}
}
delete parser;
return (handler.GetParseNum());
}
示例15: parse
//////////////////////////////////////////////////////////////////////////////
/// \brief 인수로 넘겨지는 문자열을 XML 문서로 가정하고 파싱한다.
///
/// \param buffer
//////////////////////////////////////////////////////////////////////////////
void XMLParser::parse(const char* buffer)
{
assert(buffer != NULL);
assert(m_pHandler != NULL);
// SAX 파서 오브젝트를 생성한다. 그리고 feature를 설정한다.
// feature에 관한 사항은 XMLParser::parseURL() 함수를 참고하기 바란다.
SAX2XMLReader* pParser = XMLReaderFactory::createXMLReader();
pParser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
pParser->setFeature(XMLUni::fgXercesSchema, true);
pParser->setFeature(XMLUni::fgXercesSchemaFullChecking, false);
pParser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, false);
pParser->setFeature(XMLUni::fgSAX2CoreValidation, true);
pParser->setFeature(XMLUni::fgXercesDynamic, true);
pParser->setContentHandler(m_pHandler);
pParser->setErrorHandler(m_pHandler);
try
{
MemBufInputSource source(
(const XMLByte*)(buffer), (unsigned int)strlen(buffer), "", false);
pParser->parse(source);
}
catch (const XMLException& e)
{
XMLUtil::filelog(
"\nError during parsing! Exception Message: \n%s\n",
XMLUtil::WideCharToString(e.getMessage()).c_str());
}
catch (...)
{
XMLUtil::filelog(
"Unexpected exception during parsing!\n");
}
delete pParser;
}