本文整理汇总了C++中SAX2XMLReader类的典型用法代码示例。如果您正苦于以下问题:C++ SAX2XMLReader类的具体用法?C++ SAX2XMLReader怎么用?C++ SAX2XMLReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SAX2XMLReader类的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: 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;
}
示例3: ImportFromXML
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: 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 ();
}
示例5: parseOne
static
bool parseOne(BinOutputStream* outStream
, const char* const xmlFile)
{
//we don't use janitor here
MemoryManager* theMemMgr = new MemoryManagerImpl();
XMLGrammarPool* theGramPool = new XMLGrammarPoolImpl(theMemMgr);
SAX2XMLReader* theParser = getParser(theGramPool, false); //don't emit error
bool retVal = true;
theParser->setFeature(XMLUni::fgXercesCacheGrammarFromParse, true);
//scan instance document and cache grammar
try
{
theParser->parse(xmlFile);
}
catch (...)
{
//do nothing, it could be an invalid instance document, but the grammar is fine
}
//serialize the grammar pool
try
{
theGramPool->serializeGrammars(outStream);
}
catch (const XSerializationException& e)
{
//do emit error here so that we know serialization failure
XERCES_STD_QUALIFIER cerr << "An error occurred during serialization\n Message: "
<< StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
retVal = false;
}
catch (...)
{
//do emit error here so that we know serialization failure
XERCES_STD_QUALIFIER cerr << "An error occurred during serialization\n" << XERCES_STD_QUALIFIER endl;
retVal = false;
}
//the order is important
delete theParser;
delete theGramPool;
delete theMemMgr;
return retVal;
}
示例6: DEBOUT
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;
}
示例7: assert
//////////////////////////////////////////////////////////////////////////////
/// \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;
}
示例8: 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;
}
示例9:
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;
}
示例10: LoadEx
// ---------------------------------------------------------------------------
// 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);
}
示例11: parseTwo
static
void parseTwo(BinInputStream* inStream
, const char* const xmlFile)
{
//we don't use janitor here
MemoryManager* theMemMgr = new MemoryManagerImpl();
XMLGrammarPool* theGramPool = new XMLGrammarPoolImpl(theMemMgr);
bool errorSeen = false;
//de-serialize grammar pool
try
{
theGramPool->deserializeGrammars(inStream);
}
catch(const XSerializationException& e)
{
XERCES_STD_QUALIFIER cerr << "An error occurred during de-serialization\n Message: "
<< StrX(e.getMessage()) << XERCES_STD_QUALIFIER endl;
errorSeen = true;
}
catch (...)
{
//do emit error here so that we know serialization failure
XERCES_STD_QUALIFIER cerr << "An error occurred during de-serialization\n" << XERCES_STD_QUALIFIER endl;
errorSeen = true;
}
if (!errorSeen)
{
SAX2XMLReader* theParser = getParser(theGramPool, true); //set the handler
theParser->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, true);
parseFile(theParser, xmlFile);
delete theParser;
}
//the order is important
delete theGramPool;
delete theMemMgr;
return;
}
示例12: ImportFromXML
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: TestInit4SAX2
// ---------------------------------------------------------------------------
// SAX2 XML Reader
// ---------------------------------------------------------------------------
int TestInit4SAX2(const char* xmlFile, bool gDoNamespaces, bool gDoSchema, bool gSchemaFullChecking, Teststate theState)
{
TESTINITPRE;
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
XMLCh* doNamespaceFeature = XMLString::transcode("http://xml.org/sax/features/namespaces");
parser->setFeature(doNamespaceFeature, gDoNamespaces);
XMLCh* doSchemaFeature = XMLString::transcode("http://apache.org/xml/features/validation/schema");
parser->setFeature(doSchemaFeature, gDoSchema);
XMLCh* fullSchemaCheckFeature = XMLString::transcode("http://apache.org/xml/features/validation/schema-full-checking");
parser->setFeature(fullSchemaCheckFeature, gSchemaFullChecking);
XMLString::release(&doNamespaceFeature);
XMLString::release(&doSchemaFeature);
XMLString::release(&fullSchemaCheckFeature);
TESTINITPOST;
}
示例14: ImportFromXML
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: main
// ---------------------------------------------------------------------------
// Program entry point
// ---------------------------------------------------------------------------
int main(int argC, char* argV[])
{
// Check command line and extract arguments.
if (argC < 2)
{
usage();
return 1;
}
int argInd;
for (argInd = 1; argInd < argC; argInd++)
{
// Break out on first parm not starting with a dash
if (argV[argInd][0] != '-')
break;
// Watch for special case help request
if (!strcmp(argV[argInd], "-?"))
{
usage();
return 2;
}
// TODO: add option to generate the XML summarizing the result
else if (!strncmp(argV[argInd], "-v=", 3)
|| !strncmp(argV[argInd], "-V=", 3))
{
}
else
{
XERCES_STD_QUALIFIER cout << "Unknown option '" << argV[argInd]
<< "', ignoring it\n" << XERCES_STD_QUALIFIER endl;
}
}
//
// There should be only one and only one parameter left, and that
// should be the file name.
//
if (argInd != argC - 1)
{
usage();
return 1;
}
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException& toCatch)
{
XERCES_STD_QUALIFIER cout << "Error during initialization! Message:\n"
<< StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
return 1;
}
//
// Create a SAX parser object.
//
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
parser->setFeature(XMLUni::fgSAX2CoreValidation, false);
const char* xmlFile = argV[argInd];
// Discover if the test suite is the XML or XMLSchema one
RootExtractor rootExtractor;
parser->setContentHandler(&rootExtractor);
try
{
parser->parse(xmlFile);
}
catch (...)
{
}
XMLCh* uniFile = XMLString::transcode(xmlFile);
XMLCh* uri = new XMLCh[XMLString::stringLen(xmlFile) + 9];
XMLString::fixURI(uniFile, uri);
BaseHarnessHandlers* handler=NULL;
if(rootExtractor.isXMLSuite())
{
// XML Test Suite
handler=new XMLHarnessHandlers(uri);
}
else
{
// XMLSchema Test Suite
handler=new XSTSHarnessHandlers(uri);
}
XMLString::release(&uniFile);
delete [] uri;
parser->setContentHandler(handler);
parser->setErrorHandler(handler);
//
//.........这里部分代码省略.........