• 5037阅读
  • 1回复

求各位帮我看看如何在qt中解析这个xml文件,使用Dom,Sax或其他解析器都可以,跪求、、、 [复制链接]

上一主题 下一主题
离线yinjunnan
 
只看楼主 倒序阅读 楼主  发表于: 2012-07-22
<?xml version="1.0" encoding="UTF-8"?>
<keyboard>
   <options>
         <!--not yet implentmented -->
   </options>
<layout id="coustom keyboard">
       <!--Top Row -->
   <row>
     <space width="40" extended="true"/>
     <key>
         <default display="button1"/>
         <shifted display="1"/>
     </key>
     <key>
         <default display="button2"/>
         <shifted display="2"/>
     </key>
     <key>
         <default display="button3"/>
         <shifted display="3"/>
     </key>
     <key>
         <default display="button4"/>
         <shifted display="4"/>
     </key>
     <space width="40" extended="true"/>
   </row>
        <!--Secnod Row -->
<row>
     <space width="40" extended="true"/>
     <key>
         <default display="button5"/>
         <shifted display="5"/>
     </key>
     <key>
         <default display="button6"/>
         <shifted display="6"/>
     </key>
     <key>
         <default display="button7"/>
         <shifted display="7"/>
     </key>
     <key>
         <default display="button8"/>
         <shifted display="8"/>
     </key>
     <space width="40" extended="true"/>
   </row>
       <!--Third Row -->
   <row>
     <space width="40" extended="true"/>
     <key>
         <default display="button9"/>
         <shifted display="9"/>
     </key>
     <key>
         <default display="button10"/>
         <shifted display="10"/>
     </key>
     <key>
         <default display="button11"/>
         <shifted display="11"/>
     </key>
     <key>
         <default display="button12"/>
         <shifted display="12"/>
     </key>
     <space width="40" extended="true"/>
   </row>
       <!--Fourth Row-->
   <row>
      <space width="40" extended="true"/>
   <key>
      <default display="button13"/>
<shifted display="13"/>
       </key>
       <key fill="true">
          <default display="lock" action="false"/>
       </key>
       <key fill="true">
          <default display="lock" action="false"/>
        </key>
        <key fill="true">
          <default display="Shift" action="modifier:shift"/>
          <space width="40" extended="true"/>
        </key>
        </row>
      </layout>
   </keyboard>
离线ppdayz

只看该作者 1楼 发表于: 2012-07-22
回 楼主(yinjunnan) 的帖子
QDomDocument doc("mydocument");
QFile file("mydocument.xml");
if (!file.open(QIODevice::ReadOnly))
     return;
if (!doc.setContent(&file)) {
     file.close();
     return;
}
file.close();

QDomElement docElem = doc.documentElement(); //keyboard节点,root
QDomElement optionsE = docElem.firstChildElement(options); //options节点,然后处理options
... ...
QDomElement layoutE = docElem.firstChildElement("layout");
QString layoutID = layoutE.attribute("id"); // 取得id的值coustom keyboard

QDomElement rowE = layoutE.firstChildElement("row");

while(!rowE.isNull()){
   QDomElement spaceE = rowE.firstChildElement("space");
   ... ... //处理space节点
   QDomElement keyE = rowE.firstChildElement("key");
  
  
   while(!keyE.isNull()){

       keyE = keyE.nextSiblingElement();
   }
  rowE = rowE.nextSiblingElement();
}





快速回复
限100 字节
 
上一个 下一个