QXmlQuery update of attributes

  • I'm really new with the XQuery language. I try to update an attribute value in a XML document with XQuery an the QXmlQuery class.
    I found the following example on the internet.

    XML Source:

    <root foo="bar">

    XQuery Code:

    let $doc := doc('/db/test/update-attribute/root.xml')/root
    return update value $doc/@foo with 'new-value'

    XML Result:

    <root foo="new-value">

    Is it possible to do this with QXmlQuery class?
    I tried it with the following code, but it didn't work:

    QString fileName("D:\\source.xml");
    QFile file(fileName);
    if (file.open(QIODevice::ReadOnly))
            QXmlQuery xmlQuery;
            xmlQuery.bindVariable("fileName", &file);
    	QString resultString;
    	QString queryString;
    	queryString = "declare variable $fileName external;\n";
            queryString += "let $doc := doc($fileName)/root\n";
            queryString += "return update value $doc/@foo with 'new-value'\n";
            if (xmlQuery.evaluateTo(&resultString))
    		qDebug() << resultString;

    A Query like "declare variable $fileName external; doc($fileName)/root/@foo/data(.)" works, but update operation like described above not. Is update possible with QXmlQuery class or is a newer version of the XQuery language or an extenstion necessary which QXmlQuery don't support?

Log in to reply

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