Qt World Summit: Register Today!

QXmlQuery and Xpath : cannot extract neither the node's text nor the parameter’s value

  • Hi,

    I'm trying to extract some data from an xml content. So i used QXmlQuery and wrote the code below (in Qt5). The problems are :

    1. If i try to extract text1 (so a node's text, see line 32), the code returns me the whole node : <value>text1</value>

    => Question 1 : how to get only text1 ?

    1. If i try to extract x1 (so a parameter's value, see line 35), the code returns me an error :
      Error SENR0001 in file:///C:/work/tests/build-TestXMLParser-Desktop-Debug/debug/TestXMLParser.exe, at line 1, column 1: Attribute param can't be serialized because it appears at the top level.

    => Question 2 : What i'm doing wrong ?

    Here is the code :
    #include <QApplication>

    #include <QFile>
    #include <QDebug>
    #include <QXmlQuery>
    #include <QXmlSerializer>
    #include <QXmlFormatter>
    #include <QBuffer>

    int main(int argc, char *argv[])
    QApplication a(argc, argv);

    QString xmlContent =
                "<node1 param='x1'>"
                "<node2 param='x2'>"
    QBuffer device;
    QXmlQuery query;
    query.bindVariable("inputDocument", &device);
    // Extracting "text1"
    // Exracting "x1"
    // Output value
    QByteArray outArray;
    QBuffer buffer(&outArray);
    QXmlSerializer serializer(query, &buffer);
    qWarning() << "Exracted value : " << QString::fromUtf8(outArray.constData());
    return a.exec(&#41;;



Log in to reply