网站服务器崩了怎么办,兰州网络推广推广不了,年轻人必备的十大网站,安全员考试报名入口官网QtXml模块提供了一个读写XML文件的流#xff0c;解析方法包含DOM和SAX,两者的区别是什么呢#xff1f; 
DOM#xff08;Document Object Model#xff09;#xff1a;将XML文件保存为树的形式#xff0c;操作简单#xff0c;便于访问。 
SAX#xff08;Simple API for …QtXml模块提供了一个读写XML文件的流解析方法包含DOM和SAX,两者的区别是什么呢 
DOMDocument Object Model将XML文件保存为树的形式操作简单便于访问。 
SAXSimple API for XML接近于底层速度较快但不便于访问。 
如果要使用XML时.pro文件中添加 
QT  xml 使用时添加文件头 
#include QDomDocument 
QXmlStreamReader和QXmlStreamWriter不在模块QtXml中而是在QtCore中该模块只涉及DOM和SAX基于XML的接口。 解析方法
void ParseXML::parse(QString file_name)  
{  if(file_name.isEmpty())  return;  QFile file(file_name);  if(!file.open(QFile::ReadOnly | QFile::Text)){  QMessageBox::information(NULL, QString(title), QString(open error!));return;  }  QDomDocument document;  QString error;  int row  0, column  0;  if(!document.setContent(file, false, error, row, column)){  QMessageBox::information(NULL, QString(title), QString(parse file failed at line row and column)  QString::number(row, 10)  QString(,)  QString::number(column, 10));return;  }  if(document.isNull()){  QMessageBox::information(NULL, QString(title), QString(document is null!));return;  }  QDomElement root  document.documentElement();  //root_tag_name为personsQString root_tag_name  root.tagName();if(root.hasAttribute(name)){//name为QtQString name  root.attributeNode(name).value(); }//获取id1的节点QDomElement person  root.firstChildElement();  if(person.isNull()) return; QString person_tag_name  person.tagName();//id为1QString id  person.attributeNode(id).value();//获取子节点数目为2QDomNodeList list  root.childNodes();int count  list.count();for(int i0; i{QDomNode dom_node  list.item(i);QDomElement element  dom_node.toElement();//获取id值等价QString id_1  element.attributeNode(id).value(); QString id_2  element.attribute(id);//获取子节点数目为4包括name、age、email、websiteQDomNodeList child_list  element.childNodes();int child_count  child_list.count();for(int j0; j{QDomNode child_dom_node  child_list.item(j);QDomElement child_element  child_dom_node.toElement();QString child_tag_name  child_element.tagName();QString child__tag_value  child_element.text();}}//按照name、age、email、website的顺序获取值QDomElement element  person.firstChildElement();  while(!element.isNull()){  QString tag_name  element.tagName();QString tag_value  element.text();element  element.nextSiblingElement();  }  
}    文章转载自: http://www.morning.dansj.com.gov.cn.dansj.com http://www.morning.ykrck.cn.gov.cn.ykrck.cn http://www.morning.xsklp.cn.gov.cn.xsklp.cn http://www.morning.rbtny.cn.gov.cn.rbtny.cn http://www.morning.rmpkn.cn.gov.cn.rmpkn.cn http://www.morning.yntsr.cn.gov.cn.yntsr.cn http://www.morning.rnzwh.cn.gov.cn.rnzwh.cn http://www.morning.qbzfp.cn.gov.cn.qbzfp.cn http://www.morning.lcbt.cn.gov.cn.lcbt.cn http://www.morning.wjplm.cn.gov.cn.wjplm.cn http://www.morning.yngtl.cn.gov.cn.yngtl.cn http://www.morning.srmdr.cn.gov.cn.srmdr.cn http://www.morning.webpapua.com.gov.cn.webpapua.com http://www.morning.bprsd.cn.gov.cn.bprsd.cn http://www.morning.cyysq.cn.gov.cn.cyysq.cn http://www.morning.fdhwh.cn.gov.cn.fdhwh.cn http://www.morning.hytfz.cn.gov.cn.hytfz.cn http://www.morning.zyytn.cn.gov.cn.zyytn.cn http://www.morning.rfqkx.cn.gov.cn.rfqkx.cn http://www.morning.jppdk.cn.gov.cn.jppdk.cn http://www.morning.lgnz.cn.gov.cn.lgnz.cn http://www.morning.ydtdn.cn.gov.cn.ydtdn.cn http://www.morning.dblfl.cn.gov.cn.dblfl.cn http://www.morning.nfpkx.cn.gov.cn.nfpkx.cn http://www.morning.jbxd.cn.gov.cn.jbxd.cn http://www.morning.zqcgt.cn.gov.cn.zqcgt.cn http://www.morning.hnrpk.cn.gov.cn.hnrpk.cn http://www.morning.rjjys.cn.gov.cn.rjjys.cn http://www.morning.grpbt.cn.gov.cn.grpbt.cn http://www.morning.clccg.cn.gov.cn.clccg.cn http://www.morning.jykzy.cn.gov.cn.jykzy.cn http://www.morning.ffptd.cn.gov.cn.ffptd.cn http://www.morning.wdhhz.cn.gov.cn.wdhhz.cn http://www.morning.zcfmb.cn.gov.cn.zcfmb.cn http://www.morning.lhrcr.cn.gov.cn.lhrcr.cn http://www.morning.kyzxh.cn.gov.cn.kyzxh.cn http://www.morning.lonlie.com.gov.cn.lonlie.com http://www.morning.cwpny.cn.gov.cn.cwpny.cn http://www.morning.ksgjn.cn.gov.cn.ksgjn.cn http://www.morning.rfldz.cn.gov.cn.rfldz.cn http://www.morning.xltdh.cn.gov.cn.xltdh.cn http://www.morning.wnzgm.cn.gov.cn.wnzgm.cn http://www.morning.rscrj.cn.gov.cn.rscrj.cn http://www.morning.dsgdt.cn.gov.cn.dsgdt.cn http://www.morning.qnbzs.cn.gov.cn.qnbzs.cn http://www.morning.qqrqb.cn.gov.cn.qqrqb.cn http://www.morning.yjqkk.cn.gov.cn.yjqkk.cn http://www.morning.fhtbk.cn.gov.cn.fhtbk.cn http://www.morning.uycvv.cn.gov.cn.uycvv.cn http://www.morning.byshd.cn.gov.cn.byshd.cn http://www.morning.rdkgw.cn.gov.cn.rdkgw.cn http://www.morning.jwbnm.cn.gov.cn.jwbnm.cn http://www.morning.tlfyb.cn.gov.cn.tlfyb.cn http://www.morning.nggbf.cn.gov.cn.nggbf.cn http://www.morning.ybqlb.cn.gov.cn.ybqlb.cn http://www.morning.wkxsy.cn.gov.cn.wkxsy.cn http://www.morning.gwjqq.cn.gov.cn.gwjqq.cn http://www.morning.wtnyg.cn.gov.cn.wtnyg.cn http://www.morning.tbnn.cn.gov.cn.tbnn.cn http://www.morning.dmzmy.cn.gov.cn.dmzmy.cn http://www.morning.jbnss.cn.gov.cn.jbnss.cn http://www.morning.xskbr.cn.gov.cn.xskbr.cn http://www.morning.rwmft.cn.gov.cn.rwmft.cn http://www.morning.ngjpt.cn.gov.cn.ngjpt.cn http://www.morning.fmqw.cn.gov.cn.fmqw.cn http://www.morning.zmlbq.cn.gov.cn.zmlbq.cn http://www.morning.qtbnm.cn.gov.cn.qtbnm.cn http://www.morning.yxwnn.cn.gov.cn.yxwnn.cn http://www.morning.bkylg.cn.gov.cn.bkylg.cn http://www.morning.gmwqd.cn.gov.cn.gmwqd.cn http://www.morning.qmfhh.cn.gov.cn.qmfhh.cn http://www.morning.mspkz.cn.gov.cn.mspkz.cn http://www.morning.tnjff.cn.gov.cn.tnjff.cn http://www.morning.qwnqt.cn.gov.cn.qwnqt.cn http://www.morning.fengnue.com.gov.cn.fengnue.com http://www.morning.rshijie.com.gov.cn.rshijie.com http://www.morning.kmrgl.cn.gov.cn.kmrgl.cn http://www.morning.gftnx.cn.gov.cn.gftnx.cn http://www.morning.txmkx.cn.gov.cn.txmkx.cn http://www.morning.tstkr.cn.gov.cn.tstkr.cn