本文整理汇总了C++中SAXParser类的典型用法代码示例。如果您正苦于以下问题:C++ SAXParser类的具体用法?C++ SAXParser怎么用?C++ SAXParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SAXParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dictionaryWithContentsOfFile
ValueMap dictionaryWithContentsOfFile(const std::string& fileName)
{
_resultType = SAX_RESULT_DICT;
SAXParser parser;
CCASSERT(parser.init("UTF-8"), "The file format isn't UTF-8");
parser.setDelegator(this);
parser.parse(fileName);
return _rootDict;
}
示例2: arrayWithContentsOfFile
ValueVector arrayWithContentsOfFile(const std::string& fileName)
{
_resultType = SAX_RESULT_ARRAY;
SAXParser parser;
CCASSERT(parser.init("UTF-8"), "The file format isn't UTF-8");
parser.setDelegator(this);
parser.parse(fileName);
return _rootArray;
}
示例3: dictionaryWithDataOfFile
ValueMap dictionaryWithDataOfFile(const char* filedata, int filesize)
{
_resultType = SAX_RESULT_DICT;
SAXParser parser;
CCASSERT(parser.init("UTF-8"), "The file format isn't UTF-8");
parser.setDelegator(this);
parser.parse(filedata, filesize);
return _rootDict;
}
示例4: getFrames
Vector<SpriteFrame*> getFrames(const std::string& fileName)
{
SAXParser parser;
parser.init("UTF-8");
parser.setDelegator(this);
parser.parse(fileName);
return _frames;
}
示例5: tParser
TMXFile::TMXFile(const char* pPath)
{
TMXFileParser tParser(this, pPath);
SAXParser tSAXParser;
tSAXParser.setDelegator(&tParser);
tSAXParser.parse(pPath);
if (tParser.Failed())
{
CHU_LOGERROR("failed to load tmx from '%s'.", pPath);
throw std::logic_error("LoadFailed");
}
}
示例6: parseXMLFile
bool TMXMapInfo::parseXMLFile(const std::string& xmlFilename)
{
SAXParser parser;
if (false == parser.init("UTF-8") )
{
return false;
}
parser.setDelegator(this);
return parser.parse(FileUtils::getInstance()->fullPathForFilename(xmlFilename));
}
示例7: testUndeclaredNamespaceNoPrefixes
void SAXParserTest::testUndeclaredNamespaceNoPrefixes()
{
SAXParser parser;
parser.setFeature(XMLReader::FEATURE_NAMESPACES, true);
parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, false);
try
{
std::string xml = parse(parser, XMLWriter::CANONICAL, UNDECLARED_NAMESPACE);
fail("undeclared namespace - must throw exception");
}
catch (SAXParseException&)
{
}
}
示例8: parseXMLString
bool TMXMapInfo::parseXMLString(const std::string& xmlString)
{
size_t len = xmlString.size();
if (len <= 0)
return false;
SAXParser parser;
if (false == parser.init("UTF-8") )
{
return false;
}
parser.setDelegator(this);
return parser.parse(xmlString.c_str(), len);
}
示例9: ProcessError
void
OptionsIO::loadConfiguration() {
OptionsCont& oc = OptionsCont::getOptions();
if (!oc.exists("configuration-file") || !oc.isSet("configuration-file")) {
return;
}
std::string path = oc.getString("configuration-file");
if (!FileHelpers::exists(path)) {
throw ProcessError("Could not find configuration '" + oc.getString("configuration-file") + "'.");
}
PROGRESS_BEGIN_MESSAGE("Loading configuration");
// build parser
SAXParser parser;
parser.setValidationScheme(SAXParser::Val_Auto);
parser.setDoNamespaces(false);
parser.setDoSchema(false);
// start the parsing
OptionsLoader handler;
try {
parser.setDocumentHandler(&handler);
parser.setErrorHandler(&handler);
parser.parse(path.c_str());
if (handler.errorOccured()) {
throw ProcessError("Could not load configuration '" + path + "'.");
}
} catch (const XMLException& e) {
throw ProcessError("Could not load configuration '" + path + "':\n " + TplConvert<XMLCh>::_2str(e.getMessage()));
}
oc.relocateFiles(path);
PROGRESS_DONE_MESSAGE();
}
示例10: testRSS
void SAXParserTest::testRSS()
{
SAXParser parser;
WhitespaceFilter filter(&parser);
TestEntityResolver resolver;
filter.setEntityResolver(&resolver);
parser.setFeature(XMLReader::FEATURE_EXTERNAL_GENERAL_ENTITIES, true);
parser.setFeature(XMLReader::FEATURE_EXTERNAL_PARAMETER_ENTITIES, true);
std::istringstream istr(RSS);
Poco::FileOutputStream ostr("rss.xml");
XMLWriter writer(ostr, XMLWriter::CANONICAL | XMLWriter::PRETTY_PRINT);
filter.setContentHandler(&writer);
filter.setDTDHandler(&writer);
filter.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<Poco::XML::LexicalHandler*>(&writer));
InputSource source(istr);
filter.parse(&source);
}
示例11: handleResponse
void AreFriends::handleResponse(istream & inputstream) const
{
SAXParser parser;
parser.setFeature(XMLReader::FEATURE_NAMESPACES, true);
parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true);
parser.setContentHandler(const_cast<AreFriends*>(this));
try
{
SharedPtr<InputSource> inputSource(new InputSource(inputstream));
parser.parse(inputSource);
mSuccessCallback.call(mFriendInfoList);
}
catch (Exception& e)
{
cerr << e.displayText() << endl;
mErrorCallback.call(ErrorResponse(0,e.message(), KeyValue()));
}
}
示例12: Clear
/* Read the file. */
bool GQCFileData::Read(const std::string &fileName)
{
Clear();
// Initialize the XML4C2 system
try
{
XMLPlatformUtils::Initialize();
}
catch (const XMLException&)
{
return false;
}
bool status = false;
SAXParser* parser = new SAXParser;
parser->setValidationScheme(SAXParser::Val_Never);
parser->setLoadExternalDTD(false);
parser->setDoNamespaces(false);
parser->setDoSchema(false);
parser->setValidationSchemaFullChecking(false);
SAXGenericReportHandlers handler(this);
parser->setDocumentHandler(&handler);
parser->setErrorHandler(&handler);
try
{
parser->parse(fileName.c_str());
int errorCount = parser->getErrorCount();
if (errorCount == 0)
{
status = true;
}
}
catch (...)
{
status = false;
}
delete parser;
XMLPlatformUtils::Terminate();
return status;
}
示例13: main
int main(int argc, char** argv)
{
// parse an XML document and print the generated SAX events
if (argc < 2)
{
std::cout << "usage: " << argv[0] << ": <xmlfile>" << std::endl;
return 1;
}
MyHandler handler;
SAXParser parser;
parser.setFeature(XMLReader::FEATURE_NAMESPACES, true);
parser.setFeature(XMLReader::FEATURE_NAMESPACE_PREFIXES, true);
parser.setContentHandler(&handler);
parser.setProperty(XMLReader::PROPERTY_LEXICAL_HANDLER, static_cast<LexicalHandler*>(&handler));
try
{
parser.parse(argv[1]);
}
catch (Poco::Exception& e)
{
std::cerr << e.displayText() << std::endl;
return 2;
}
return 0;
}
示例14: return
int InstallationParser::parse() {
if (initialization() == 1) // Problem during the initialisation.
return(1);
SAXParser* parser = new SAXParser();
parser->setDoValidation(true);
parser->setDoNamespaces(true);
InstallationSAXHandler* handler = new InstallationSAXHandler();
parser->setDocumentHandler(handler);
parser->setErrorHandler(handler);
try {
const char* file = xmlFile.c_str(); // Name of the descriptor file in the current directory.
parser->parse(file); // Parsing procedure.
handler->get_pkgname(pkgname); // Result of the parsing.
handler->get_pkgUUID(pkgUUID);
handler->get_implementations(codefiles); // Result of the parsing.
}
catch (const XMLException& toCatch) { // File not found for the parsing.
std::cerr << "\nFile not found : '" << xmlFile << "'\n";
std::cerr << "Exception message is : \n" << toCatch.getMessage() << "\n";
return(4);
}
int err = handler->get_error(); // The error codes are got from the handler object.
delete(handler); // Object deleted.
delete(parser); // Object deleted.
return(err); // 0, 2 or 3 is returned.
}
示例15: init_xml_dom
bool
Kumu::XMLElement::ParseString(const char* document, ui32_t doc_len)
{
if ( doc_len == 0 )
return false;
init_xml_dom();
int errorCount = 0;
SAXParser* parser = new SAXParser();
parser->setValidationScheme(SAXParser::Val_Always);
parser->setDoNamespaces(true); // optional
MyTreeHandler* docHandler = new MyTreeHandler(this);
parser->setDocumentHandler(docHandler);
parser->setErrorHandler(docHandler);
try
{
MemBufInputSource xmlSource(reinterpret_cast<const XMLByte*>(document),
static_cast<const unsigned int>(doc_len),
"pidc_rules_file");
parser->parse(xmlSource);
}
catch (const XMLException& e)
{
char* message = XMLString::transcode(e.getMessage());
DefaultLogSink().Error("Parser error: %s\n", message);
XMLString::release(&message);
errorCount++;
}
catch (const SAXParseException& e)
{
char* message = XMLString::transcode(e.getMessage());
DefaultLogSink().Error("Parser error: %s at line %d\n", message, e.getLineNumber());
XMLString::release(&message);
errorCount++;
}
catch (...)
{
DefaultLogSink().Error("Unexpected XML parser error\n");
errorCount++;
}
if ( errorCount == 0 )
m_NamespaceOwner = (void*)docHandler->TakeNamespaceMap();
delete parser;
delete docHandler;
return errorCount > 0 ? false : true;
}