Qt QtXml read xml file content
xml file content
<?xml version="1.0" encoding="UTF-8"?> <YG_RTLS> <Anchor_list> <Anchor z="0" id="1" MA_ID="" y="1789" x="50" ant_dly="" type="2"/> <Anchor z="0" id="2" MA_ID="" y="1840" x="2970" ant_dly="" type="2"/> <Anchor z="0" id="3" MA_ID="" y="70" x="2940" ant_dly="" type="2"/> <Anchor z="0" id="4" MA_ID="" y="9" x="-19" ant_dly="" type="2"/> </Anchor_list> <Anchor_Group id="1" map_id="0" type="2"> <Member id="1"/> <Member id="2"/> <Member id="3"/> <Member id="4"/> </Anchor_Group> <CONFIG version="1"/> </YG_RTLS>
// read the profile data base void readSysConfigFileData (QString sysConfigFileName) { // Open the file or create the QFile xmlFile (sysConfigFileName); IF (! XmlFile.open (the QFile :: the ReadOnly)) { return ; } QDomDocument docXML; IF (! docXML.setContent (& xmlFile)) { xmlFile.close (); return ; } xmlFile.close (); QDomElement XmlRoot = docXML.documentElement (); // return the root node QDomNode xmlRoot.firstChild domNode = (); // get The first child while(! domNode.isNull ()) // if the node is not empty { IF (domNode.isElement ()) // if the node is an element { QDomElement the domElement = domNode.toElement (); // convert elements, and that an element node is two data structures, in fact, almost QDomNodeList List = domElementchildNodes (); for ( int I = 0 ; I <list.count (); I ++) // traverse the sub-elements, count and size can be used, the label can be used to count the number of { nodeIndex QDomNode = list.at (I); IF (domNode.isElement ()) { QDomElement indexElement= nodeIndex.toElement(); if (indexElement.hasAttribute("x")) { qDebug() << nodeIndex.nodeName() << ":" << nodeIndex.toElement().attribute("id") << " " << nodeIndex.toElement().attribute("x") << " " << nodeIndex.toElement().attribute("y") << " "NodeIndex.toElement << () attribute (. " Z"); } } } } // next sibling node, nextSiblingElement () is the next sibling domNode = domNode.nextSibling (); } }
Export
"Anchor" : "1" "50" "1789" "0"
"Anchor" : "2" "2970" "1840" "0"
"Anchor" : "3" "2940" "70" "0"
"Anchor" : "4" "-19" "9" "0"