XML Query



  • Hello all.
    I need to write at xml my query.
    And then I want to read it at QT.

    Where to start? Tell me some examples.


  • Qt Champions 2016

    @Taz742

    Hi
    Its not clear what you mean but writing XML can be done with
    http://doc.qt.io/qt-5/qxmlstreamwriter.html

    https://gist.github.com/lamprosg/2133804





  • The idea to have such a thing, all my query placed at XML, and then switch the program to read it and keep at QMap.



  • <?xml version="1.0" encoding="UTF-8"?>
    
    <scriptpak>
    	<queryname>GET USERS</queryname>
    	<queryvalue>SELECT * FROM USERS</queryvalue>
    	
    	<queryname>GET VALUTANAME</queryname>
    	<queryvalue>SELECT ValutaName FROM VALUTA</queryvalue>
    	
    	<queryname>INSERT USER</queryname>
    	<queryvalue>some query..</queryvalue>
    	
    	<queryname>UPDATE</queryname>
    	<queryvalue>some query..</queryvalue>
    </scriptpak
    

    QMap<QString,QString> my_map;

    my_map["GET USERS"] = "SELECT * FROM USERS";
    my_map["GET VALUTANAME"] = "SELECT ValutaName FROM VALUTA";



  • solved:

    QMap<QString, QString> my_map;
       QString key = "", value = "";
    
       QFile* file = new QFile("C:/Users/tleladze/Desktop/user_/QUERYS/queryxml.xml");
    
       if(!file->open(QIODevice::ReadOnly | QIODevice::Text)){
           qDebug() << "Filed To Open Xml";
           return -1;
       }
    
       QXmlStreamReader* xml = new QXmlStreamReader(file);
    
       while(!xml->atEnd()){
    
           QXmlStreamReader::TokenType token = xml->readNext();
    
           if(token == QXmlStreamReader::StartDocument)
               qDebug() << "aaa";
    
           if(xml->name() == "scriptpak"){
               qDebug() << "bbb";
           }
    
           if(xml->name() == "queryname"){
                 key = xml->readElementText();
                 qDebug() << key;
           }
    
           if(xml->name() == "queryvalue"){
               value = xml->readElementText();
               qDebug() << value;
           }
    
           my_map[key] = value;
       }
    
       for(auto e : my_map.keys())
       {
           qDebug() << e << ":" << my_map.value(e) << '\n';
       }
    

    answer:

    aaa
    bbb
    "GET USERS"
    "SELECT * FROM USERS"
    "GET VALUTANAME"
    "SELECT ValutaName FROM VALUTA"
    "INSERT USER"
    "some query.."
    "UPDATE"
    "some query.."
    bbb
    "" : "" 
    
    "GET USERS" : "SELECT * FROM USERS" 
    
    "GET VALUTANAME" : "SELECT ValutaName FROM VALUTA" 
    
    "INSERT USER" : "some query.." 
    
    "UPDATE" : "some query.." 
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.