XML parsing in QT

1.1k views Asked by At

I am new to QT

I am developing application to parse the XML file. But the File format looks like this

 <Class name="ABC">
    <LayoutEntry name="ABB"            type="class:ABB"/>
    <LayoutEntry name="ACC"            type="class:ACC"/>
    <LayoutEntry name="ADD"            type="class:ADD"/>
 </Class>

 <Class name="ABB">   //Declared  in class ABC
    <LayoutEntry name="ABB1"            type="class:ABB1"/>
    <LayoutEntry name="ABB2"            type="class:ABB2"/>
  </Class>

  <Class name="ABB1">  //Declared in class ABB
    <LayoutEntry name="ABB1"            value=ABB1"/>
  </Class>

  <Class name="ABB2">
    <LayoutEntry name="ABB2"            value=ABB2"/>
  </Class>

Please some one suggest me for any library or method in QT to parse this type of XML . Thanks

3

There are 3 answers

2
KimKulling On BEST ANSWER

You can use the module QtXML 5.8, which is part of the Qt-framework. There you can find the class QDomDocument ( QDomDocument-doc ) for instance.

0
baddger964 On

You can use QDomDocument and all class starting with qDom. This way you can get a object corresponding to your document. Each markup will be a QDomNode and you can call method like getParam, getChild or getParent.

0
Subrata Das On
           QDomNodeList list;
           list = document.elementsByTagName("Parent");
           int ChildCount = list.at(0).childNodes().count();
           qDebug() << "ChildCount = " << ChildCount;
           QString child1,child2,child3;
            for(int i=0; i < ChildCount; i++)
            { 
             child1 = list.at(0).childNodes().at(0).toElement().text();
             child2 = list.at(0).childNodes().at(1).toElement().text();
             child3 = list.at(0).childNodes().at(2).toElement().text();
            }