当前位置: 首页 > news >正文

做直播网站找哪家网站好wordpress主题分享博客

做直播网站找哪家网站好,wordpress主题分享博客,专门做金融培训的网站有哪些,wordpress安全设置方法Qt的Xml操作QDomDocument Qt对于Xml的支持是很好的#xff0c;一些我们需要的操作应有尽有#xff0c;下面简单介绍一下怎样使用。主要有以下几点使用#xff1a; 写xml到文件读xml添加节点到xml删除xml中某节点信息修改xml中某节点信息 准备工作 .pro加入QT xml需要in…Qt的Xml操作QDomDocument Qt对于Xml的支持是很好的一些我们需要的操作应有尽有下面简单介绍一下怎样使用。主要有以下几点使用 写xml到文件读xml添加节点到xml删除xml中某节点信息修改xml中某节点信息 准备工作 .pro加入QT xml需要include QDomDocument QTextStream QFile三个头文件 WriteXml 直接上代码 void writeXml() {QDomDocument doc;QDomProcessingInstruction xmlInstruction doc.createProcessingInstruction(xml, version\1.0\ encoding\UTF-8\ standalone\yes\);QDomComment comment doc.createComment(QString::fromLocal8Bit(离开是为了更好的归来));QDomProcessingInstruction styleInstruction doc.createProcessingInstruction(xml-stylesheet, type\text/css\ href\style.css\);doc.appendChild(xmlInstruction); // 开始文档XML 声明doc.appendChild(comment); // 注释doc.appendChild(styleInstruction); // 处理指令// 根元素 BlogsQDomElement root doc.createElement(Books);root.setAttribute(Version, 1.0); // 属性doc.appendChild(root);// 元素 BlogQDomElement child doc.createElement(Book);root.appendChild(child);// 元素 作者、时间、个人说明QDomElement author doc.createElement(QString::fromLocal8Bit(作者));QDomElement home doc.createElement(QString::fromLocal8Bit(时间));QDomElement instruction doc.createElement(QString::fromLocal8Bit(个人说明));child.appendChild(author);child.appendChild(home);child.appendChild(instruction);// 元素的文本数据QDomText authorText doc.createTextNode(QString::fromLocal8Bit(Vincent));QDomText homeText doc.createTextNode(2017年4月13日);QDomText instructionText doc.createTextNode(QString::fromLocal8Bit(大宋枢密院常任委员会_委员));author.appendChild(authorText);home.appendChild(homeText);instruction.appendChild(instructionText);// 保存 XML 文件QString strFile(Books.xml);QFile file(strFile);// 只写模式打开文件if (file.open(QFile::WriteOnly | QFile::Text)){QTextStream out(file);doc.save(out, QDomNode::EncodingFromDocument);file.close();} } void writeXML() {//打开或创建文件QString fileName{test.xml};QFile file(fileName);//QIODevice::Truncate表示清空原来的内容if(!file.open(QFile::WriteOnly|QFile::Truncate))return;//创建xml文档在内存中QDomDocument doc;//添加处理命令QDomProcessingInstruction instruction;instruction doc.createProcessingInstruction(xml, version\1.0\ encoding\UTF-8\);//创建注释QDomComment comment;comment doc.createComment(QString::fromLocal8Bit(离开是为了更好的归来));QDomProcessingInstruction styleInstruction;styleInstruction doc.createProcessingInstruction(xml-stylesheet, type\text/css\ href\style.css\);doc.appendChild(instruction); //文档开始声明doc.appendChild(comment);doc.appendChild(styleInstruction); // 处理指令//添加根节点QDomElement rootdoc.createElement(library);root.setAttribute(Version,2.1);doc.appendChild(root);//添加第一个子节点及其子元素QDomElement bookdoc.createElement(book);//方式一创建属性 其中键值对的值可以是各种类型book.setAttribute(id,1);//方式二创建属性 值必须是字符串QDomAttr timedoc.createAttribute(time);time.setValue(2013/6/13);book.setAttributeNode(time);QDomElement titledoc.createElement(title); //创建子元素QDomText text; //设置括号标签中间的值textdoc.createTextNode(C primer);book.appendChild(title);title.appendChild(text);QDomElement authordoc.createElement(author); //创建子元素textdoc.createTextNode(Stanley Lippman);author.appendChild(text);book.appendChild(author);//添加节点book做为根节点的子节点root.appendChild(book);//添加第二个子节点及其子元素bookdoc.createElement(book);book.setAttribute(id,2);timedoc.createAttribute(time);time.setValue(2007/5/25);book.setAttributeNode(time);titledoc.createElement(title);textdoc.createTextNode(Thinking in Java);book.appendChild(title);title.appendChild(text);authordoc.createElement(author);textdoc.createTextNode(Bruce Eckel);author.appendChild(text);book.appendChild(author);root.appendChild(book);//输出到文件QTextStream out_stream(file);doc.save(out_stream,4); //缩进4格file.close(); } ReadXml 上代码 void readXML() {//打开或创建文件QFile file(test.xml);if(!file.open(QFile::ReadOnly))return;QDomDocument doc;//设置wangfei1.xml到文档if(!doc.setContent(file)){file.close();return;}file.close();//返回根节点QDomElement rootdoc.documentElement();qDebug()root.nodeName();//如果xml根元素有属性Version将输出Vinsion是用户自定义的属性没有继续执行下一条命令if (root.hasAttribute(Version)) // 属性qDebug() root.attribute(Version);/**********根元素之上XML 声明、注释等**********/QDomNode node root.previousSibling();while (!node.isNull()){switch (node.nodeType()){case QDomNode::ProcessingInstructionNode :{QDomProcessingInstruction instruction node.toProcessingInstruction();//输出处理指令是用户自定义的比如字符串“name”对应处理指令得到名字这个命令是用户写的qDebug() instruction.target() instruction.data();if (QString::compare(instruction.target(), xml) 0) // 开始文档XML 声明{//cout处理命令xmlendl;// ...}else if (QString::compare(instruction.target(), xml-stylesheet) 0) // 处理指令{//cout处理命令xml-stylesheetendl;// ...}break;}case QDomNode::CommentNode :{QDomComment comment node.toComment();qDebug() comment.data();break;}default:break;}node node.previousSibling();}//获得第一个子节点noderoot.firstChild();while(!node.isNull()) //如果节点不空{if(node.isElement()) //如果节点是元素{//转换为元素QDomElement elementnode.toElement();if (!element.isNull())// 节点的确是一个元素{//输出第一个节点包括第一个节点的属性这个属性需要指定属性值才能输出如果没有输出空qDebug()element.tagName() element.attribute(id) element.attribute(time);QDomNodeList listelement.childNodes();for(int i0;ilist.count();i){QDomNode nlist.at(i);//node list.at(i);if(node.isElement()){qDebug()n.nodeName():n.toElement().text();element n.toElement();//qDebug()element.nodeName():element.toElement().text();if (QString::compare(element.tagName(), QStringLiteral(作者)) 0){// ...处理命令//cout 处理命令作者endl;}else if (QString::compare(element.tagName(), QStringLiteral(时间)) 0){//cout处理命令时间endl;// ...处理命令}else if (QString::compare(element.tagName(), QStringLiteral(个人说明)) 0){//cout处理命令个人说明endl;// ...处理命令}}}}}//下一个兄弟节点nodenode.nextSibling();} } AddXml void addXML() {//打开文件QFile file(test.xml);if(!file.open(QFile::ReadOnly))return;//增加一个一级子节点以及元素QDomDocument doc;if(!doc.setContent(file)){file.close();return;}file.close();//创建根节点QDomElement root doc.documentElement();//创建next子节点bookQDomElement book doc.createElement(book);book.setAttribute(id,3);book.setAttribute(time,1813/1/27);QDomElement title doc.createElement(title);QDomText text;text doc.createTextNode(Pride and Prejudice);//添加text内容到title节点title.appendChild(text);//添加title到book节点book.appendChild(title);//添加book到根节点root.appendChild(book);if(!file.open(QFile::WriteOnly|QFile::Truncate))return;//输出到文件QTextStream out_stream(file);doc.save(out_stream,4); //以缩进4格方式输出也有其他输出方式格式file.close(); } DeleteXml void deleteXML() {//打开文件QFile file(test.xml);if(!file.open(QFile::ReadOnly))return;//删除一个一级子节点及其元素外层节点删除内层节点于此相同QDomDocument doc;if(!doc.setContent(file)){file.close();return;}file.close();QDomElement rootdoc.documentElement();//由标签名定位本标签为book以后可以是用string类型的字符串替换实现动态QDomNodeList listdoc.elementsByTagName(book);//删除方式一通过标签book后面的属性删除book到/bookfor(int i0;ilist.count();i){//转化为元素QDomElement elist.at(i).toElement();//找到time是2007/5/25这一条数据将其删除if(e.attribute(time)2007/5/25)root.removeChild(list.at(i));}//删除方式二可以通过索引直接删除 // root.removeChild(list.at(1));if(!file.open(QFile::WriteOnly|QFile::Truncate))return;//输出到文件QTextStream out_stream(file);doc.save(out_stream,4); //缩进4格file.close(); } AmendXml void amendXML() {//打开文件QFile file(wangfei1.xml);if(!file.open(QFile::ReadOnly))return;//更新一个标签项,如果知道xml的结构直接定位到那个标签上定点更新//或者用遍历的方法去匹配tagname或者attributvalue来更新QDomDocument doc;//设置wangfei.xml读到doc文档if(!doc.setContent(file)){file.close();return;}file.close();/*** 知道xml结构直接定位修改* 提取根节点**/QDomElement rootdoc.documentElement();//以book标签存入list // QDomNodeList listroot.elementsByTagName(book); // QDomNode listNodelist.at(list.size()-2).firstChild(); // QDomNode oldnodelistNode.firstChild(); // //把title改成Emma // listNode.firstChild().setNodeValue(aaaaaaa); // QDomNode newnodelistNode.firstChild(); // listNode.replaceChild(newnode,oldnode);//使用遍历方法选择要修改的元素 // QDomNodeList lists doc.childNodes(); // QDomNodeList listroot.elementsByTagName(book);QDomNode node root.firstChild();//QDomNodeList listroot.elementsByTagName(book);while(!node.isNull()) //如果节点不空{if(node.isElement()) //如果节点是元素{//转换为元素QDomElement elementnode.toElement();if (!element.isNull() element.attribute(id) 3)// 节点的确是一个元素{//输出第一个节点包括第一个节点的属性这个属性需要指定属性值才能输出如果没有输出空//qDebug()element.tagName() element.attribute(id) element.attribute(time);QDomNodeList listelement.childNodes();for(int i0;ilist.count();i){QDomNode nlist.at(i);//node list.at(i);if(node.isElement()){//qDebug()n.nodeName():n.toElement().text();element n.toElement();//与上面qDebug效果相同//qDebug()element.nodeName():element.toElement().text();//这个if可以不需要如果需要精确定位以防数据相同所以要加这个嵌套ifif (QString::compare(element.tagName(), QStringLiteral(title)) 0){if(Pride and Prejudice element.toElement().text()){// ...处理命令在这个if里可以遍历想要的节点进行修改//新建一个旧的node缓存QDomNode oldNode n.firstChild();n.firstChild().setNodeValue(changchun1);//新建一个新的newNode子节点QDomNode newNode n.firstChild();//使用replaceChild替换noden.replaceChild(newNode,oldNode);}}else if (QString::compare(element.tagName(), QStringLiteral(时间)) 0){//cout处理命令时间endl;// ...处理命令}else if (QString::compare(element.tagName(), QStringLiteral(个人说明)) 0){//cout处理命令个人说明endl;// ...处理命令}}}}}//下一个兄弟节点nodenode.nextSibling();}if(!file.open(QFile::WriteOnly|QFile::Truncate))return;//输出到文件QTextStream out_stream(file);doc.save(out_stream,4); //缩进4格file.close();}
http://www.sadfv.cn/news/166067/

相关文章:

  • 优秀个人网站模板上海校园兼职网站建设
  • 营销策划案的模板昆明seo网站排名优化
  • 广州中心网站建设外贸营销网站建设公司
  • 广州哪家网站建设公司好怎么才能免费建网站
  • 曲阳路街道网站建设网站开发手机号能在页面上显示吗
  • 昆山app网站制作上海 企业网站制
  • 个人网站方案建设书建设银行网站转账必须u盾吗
  • 国外化工网站模板wordpress整站密码
  • 中国公路建设协会网站网站收录在哪里可以查看
  • 高碑店网站网站建设网络建站免费网址
  • 仿京东网站模板淘宝网官网
  • 网页设计与网站建设简答题网页游戏排行榜前十推荐
  • 如何查找网站所有页面wordpress 注册验证码
  • 实时开奖走势网站建设济南建网站要
  • 柳州专业网站推广公司nancy网站开发
  • 网站seo优化外包dw网页制作考试题目
  • 网站制作成品下载必应搜索引擎首页
  • 做卷闸门网站有用吗公司简介简短
  • 建设网站运营方案制作排行榜的软件
  • 营销型网站维护费用飓风seo刷排名软件
  • 网络推广外包公司一般在哪里招聘沈阳网站制作优化推广
  • 男女性做那个视频网站推销网站建设
  • 网站开发方案 ppt小程序注册条件
  • 福州网站营销led wordpress
  • 做网站联盟那些网站反爬做的好
  • 社交网站建设流程如何弄微信小程序
  • 手机企业网站模板防腐木用什么名字做网站
  • 外贸高端网站定制哪里做网站需求
  • 建设银行指定网站怎么做网站代理
  • 网站运营费用不用下载的行情网站