Parse a xml file using c++ & Qt

后端 未结 3 1874
夕颜
夕颜 2021-02-09 19:51

I try to parse a XML-file with the following structure:


  
     
        

        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-09 20:35

    you could use QXmlQuery. It act like XQuery (i guess the syntax is the same). And you could parse your xml file with the big advantage of XQuery's flexibility. You can start with a code like this:

    QByteArray myDocument;
    QBuffer buffer(&myDocument); // This is a QIODevice.
    buffer.open(QIODevice::ReadOnly);
    QXmlQuery query;
    query.bindVariable("myDocument", &buffer);
    query.setQuery("doc($myDocument)");
    

    setQuery method allow you to define your search pattern. It can be based on element id, attribute, and so on...as with XQuery. This is QXmlQuery doc page: link

提交回复
热议问题