本文整理汇总了C++中MyParser::set_skip_whitespaces方法的典型用法代码示例。如果您正苦于以下问题:C++ MyParser::set_skip_whitespaces方法的具体用法?C++ MyParser::set_skip_whitespaces怎么用?C++ MyParser::set_skip_whitespaces使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyParser
的用法示例。
在下文中一共展示了MyParser::set_skip_whitespaces方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
MyParser p;
ifstream is;
string xml;
string chunk;
char buff[64];
int len;
// disable CDATA composed of whitespaces
p.set_skip_whitespaces(true);
// check if one (only one) file name given
if (argc != 2) {
cout<<"usage: xmlsp_test2 xml_file_to_parse"<<endl;
return 0;
}
// open input file
is.open(argv[1]);
if (!is) {
cerr<<"File \""<<argv[1]<<"\" can not be opened"<<endl;
return 1;
}
// begin parsing
if (!p.begin()) {
cerr<<"Failed to initialize parser"<<endl;
return 1;
}
// first parse use chunks
cout<<"Parsing \""<<argv[1]<<"\" as stream:"<<endl;
// read chunks, parse them, and save for one chunk parse
while (!is.eof() && is.good()) {
// read file
is.read(buff, 64);
len = is.gcount();
xml.append(buff, len);
chunk.assign(buff, len);
// try to parse
if (p.parse_chunk(chunk) == false) {
cout<<"Failed to parse chunk"<<endl;
is.close();
return 1;
}
}
if (is.bad()) {
cerr<<"Reading file failed"<<endl;
is.close();
return 1;
}
is.close();
if (!p.end()) {
cerr<<"Failed to finalize parsing"<<endl;
return 1;
}
cout<<"Parse 1 finished"<<endl<<endl<<endl;
cout<<"Parsing \""<<argv[1]<<"\" as single chunk:"<<endl;
if (p.parse(xml)) {
cout<<"Parse 2 finished"<<endl;
} else {
cerr<<"Failed to parse xml file"<<endl;
}
}