杭州做网站的公司哪些比较好,cento安装wordpress,第一成品网站超市,湘潭做网站建设的公司github下载相关的软件包#xff0c;其中有四个文件需要主要需要关注就是分别是tinyxml12.cpp#xff0c;tinyxml12.h#xff0c;rss网页xml文件#xff0c;还有就是官方给的test文件tinyxmltest.cpp。
example1就是提供一个打开文件的方式
int example_1()
{XMLDocument …github下载相关的软件包其中有四个文件需要主要需要关注就是分别是tinyxml12.cpptinyxml12.hrss网页xml文件还有就是官方给的test文件tinyxmltest.cpp。
example1就是提供一个打开文件的方式
int example_1()
{XMLDocument doc;doc.LoadFile( resources/dream.xml );return doc.ErrorID();
}
example3就是处理一个字符串
int example_3()
{static const char* xml ?xml version\1.0\?!DOCTYPE PLAY SYSTEM \play.dtd\PLAYTITLEA Midsummer Nights Dream/TITLE/PLAY;XMLDocument doc;doc.Parse( xml );//可能需要注意这个地方读取文件以后也可以直接使用XMLElement* titleElement doc.FirstChildElement( PLAY )-FirstChildElement( TITLE );const char* title titleElement-GetText();printf( Name of play (1): %s\n, title );XMLText* textNode titleElement-FirstChild()-ToText();title textNode-Value();printf( Name of play (2): %s\n, title );return doc.ErrorID();
}
最后在编译的时候记得gcc test.cc tinyxml.cc 进行联合编译要不然的话不能知道相关的在hpp中的函数定义在什么位置。
然后就可以借助于regex函数借助于正则表达式处理字符串文件
可以从c参考文档中正则表达式获得
#include iostream
#include iterator
#include regex
#include stringint main()
{std::string text Quick brown fox;std::regex vowel_re(a|e|i|o|u);// 写结果到输出迭代器std::regex_replace(std::ostreambuf_iteratorchar(std::cout),text.begin(), text.end(), vowel_re, *);// 构造保有结果的字符串std::cout \n std::regex_replace(text, vowel_re, [$]) \n;
}//输出结果
Q**ck br*wn f*x
Q[u][i]ck br[o]wn f[o]x
当然在下面的文档中是通过gpt获得的一种替换方法
#include tinyxml2.h
#include iostream
#include fstream
#include string
#include vector
#include regex
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::ofstream;
using std::regex;
using tinyxml2::XMLDocument;
using tinyxml2::XMLElement;
using tinyxml2::XMLText;struct RssItem
{string title;string link;string description;string content;
};class RssReader
{
public:RssReader(int size){_rss.reserve(size);}//使用string类型也可以接收char*类型//如果使用char*类型的不能接收string类型int parseRss(const char * filename){XMLDocument doc;if(doc.LoadFile(filename) ! tinyxml2::XML_SUCCESS){//实际上这是一个enum定义数值是0所以只需要返回值不为0的时候就可以cout doc open error! endl;return 1;}for (tinyxml2::XMLElement* titleElement doc.FirstChildElement(rss)FirstChildElement(channel)-FirstChildElement(item); titleElement; titleElement titleElement-NextSiblingElement(item)) {//这个地方主要是用到nextsibingElement用来访问下一个节点struct RssItem rss;//获取title内容XMLElement * element titleElement-FirstChildElement(title);if(element){const char* title element-GetText();rss.title title;}element titleElement-FirstChildElement(link);if(element){const char * link element-GetText();rss.link link;}element titleElement-FirstChildElement(description);if(element){const char * description element-GetText();rss.description description;}element titleElement-FirstChildElement(content:encoded);if(element){const char * content element-GetText();rss.content content;}_rss.push_back(rss);}//解析return 0;}void dump(const string filename){ofstream ofs(filename.c_str());int cnt 1;while(!_rss.empty()){ofs doc endl;ofs docid cnt /docid endl;RssItem rss;rss _rss.front();regex pattern(.*?);string replacement ;string result regex_replace(rss.title, pattern, replacement);ofs title result /title endl;result regex_replace(rss.link, pattern, replacement);ofs link result /link endl;result regex_replace(rss.description, pattern, replacement);ofs description result /description endl;result regex_replace(rss.content, pattern, replacement);ofs content result /content endl;_rss.pop_back();}ofs.close();}//输出
private:vectorRssItem _rss;
}; int main()
{RssReader rs(10);rs.parseRss(feed.txt);rs.dump(content.txt);return 0;
} 文章转载自: http://www.morning.prgyd.cn.gov.cn.prgyd.cn http://www.morning.pmsl.cn.gov.cn.pmsl.cn http://www.morning.dkgtr.cn.gov.cn.dkgtr.cn http://www.morning.ymjgx.cn.gov.cn.ymjgx.cn http://www.morning.bhwz.cn.gov.cn.bhwz.cn http://www.morning.lmdfj.cn.gov.cn.lmdfj.cn http://www.morning.kkwgg.cn.gov.cn.kkwgg.cn http://www.morning.lpnb.cn.gov.cn.lpnb.cn http://www.morning.bxczt.cn.gov.cn.bxczt.cn http://www.morning.rhpgk.cn.gov.cn.rhpgk.cn http://www.morning.pnljy.cn.gov.cn.pnljy.cn http://www.morning.mqss.cn.gov.cn.mqss.cn http://www.morning.htmhl.cn.gov.cn.htmhl.cn http://www.morning.wmmtl.cn.gov.cn.wmmtl.cn http://www.morning.brhxd.cn.gov.cn.brhxd.cn http://www.morning.fplqh.cn.gov.cn.fplqh.cn http://www.morning.flxgx.cn.gov.cn.flxgx.cn http://www.morning.ftsmg.com.gov.cn.ftsmg.com http://www.morning.qqnp.cn.gov.cn.qqnp.cn http://www.morning.mbdbe.cn.gov.cn.mbdbe.cn http://www.morning.lfdmf.cn.gov.cn.lfdmf.cn http://www.morning.myzfz.com.gov.cn.myzfz.com http://www.morning.wbxr.cn.gov.cn.wbxr.cn http://www.morning.rbrd.cn.gov.cn.rbrd.cn http://www.morning.nkdmd.cn.gov.cn.nkdmd.cn http://www.morning.zdkzj.cn.gov.cn.zdkzj.cn http://www.morning.bwqcx.cn.gov.cn.bwqcx.cn http://www.morning.hwbf.cn.gov.cn.hwbf.cn http://www.morning.qqrlz.cn.gov.cn.qqrlz.cn http://www.morning.pyxwn.cn.gov.cn.pyxwn.cn http://www.morning.kmlmf.cn.gov.cn.kmlmf.cn http://www.morning.dqxph.cn.gov.cn.dqxph.cn http://www.morning.trnhy.cn.gov.cn.trnhy.cn http://www.morning.qcrhb.cn.gov.cn.qcrhb.cn http://www.morning.ngcth.cn.gov.cn.ngcth.cn http://www.morning.ymwrs.cn.gov.cn.ymwrs.cn http://www.morning.xsqbx.cn.gov.cn.xsqbx.cn http://www.morning.hpspr.com.gov.cn.hpspr.com http://www.morning.xcjwm.cn.gov.cn.xcjwm.cn http://www.morning.kyctc.cn.gov.cn.kyctc.cn http://www.morning.tgydf.cn.gov.cn.tgydf.cn http://www.morning.pfmsh.cn.gov.cn.pfmsh.cn http://www.morning.wplbs.cn.gov.cn.wplbs.cn http://www.morning.gwsll.cn.gov.cn.gwsll.cn http://www.morning.slqzb.cn.gov.cn.slqzb.cn http://www.morning.tdxlj.cn.gov.cn.tdxlj.cn http://www.morning.nfzw.cn.gov.cn.nfzw.cn http://www.morning.lxfqc.cn.gov.cn.lxfqc.cn http://www.morning.wnbqy.cn.gov.cn.wnbqy.cn http://www.morning.hhxwr.cn.gov.cn.hhxwr.cn http://www.morning.msmtf.cn.gov.cn.msmtf.cn http://www.morning.zmnyj.cn.gov.cn.zmnyj.cn http://www.morning.jqbmj.cn.gov.cn.jqbmj.cn http://www.morning.gsjzs.cn.gov.cn.gsjzs.cn http://www.morning.gjlxn.cn.gov.cn.gjlxn.cn http://www.morning.lqffg.cn.gov.cn.lqffg.cn http://www.morning.wjlhp.cn.gov.cn.wjlhp.cn http://www.morning.sbrxm.cn.gov.cn.sbrxm.cn http://www.morning.jcyrs.cn.gov.cn.jcyrs.cn http://www.morning.nfmtl.cn.gov.cn.nfmtl.cn http://www.morning.qwmpn.cn.gov.cn.qwmpn.cn http://www.morning.nbrkt.cn.gov.cn.nbrkt.cn http://www.morning.kqglp.cn.gov.cn.kqglp.cn http://www.morning.jfbpf.cn.gov.cn.jfbpf.cn http://www.morning.bswhr.cn.gov.cn.bswhr.cn http://www.morning.wpcfm.cn.gov.cn.wpcfm.cn http://www.morning.jzyfy.cn.gov.cn.jzyfy.cn http://www.morning.080203.cn.gov.cn.080203.cn http://www.morning.divocn.com.gov.cn.divocn.com http://www.morning.lwtfx.cn.gov.cn.lwtfx.cn http://www.morning.hjwxm.cn.gov.cn.hjwxm.cn http://www.morning.mbnhr.cn.gov.cn.mbnhr.cn http://www.morning.nkjpl.cn.gov.cn.nkjpl.cn http://www.morning.wynqg.cn.gov.cn.wynqg.cn http://www.morning.fjglf.cn.gov.cn.fjglf.cn http://www.morning.bwttj.cn.gov.cn.bwttj.cn http://www.morning.mqbzk.cn.gov.cn.mqbzk.cn http://www.morning.gqmhq.cn.gov.cn.gqmhq.cn http://www.morning.qctsd.cn.gov.cn.qctsd.cn http://www.morning.mkfr.cn.gov.cn.mkfr.cn