Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QXmlQuery update of attributes
Forum Updated to NodeBB v4.3 + New Features

QXmlQuery update of attributes

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 879 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    blgis
    wrote on last edited by
    #1

    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">
        <message>Hello!</message>
    </root>
    

    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">
        <message>Hello!</message>
    </root>
    

    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";
    	xmlQuery.setQuery(queryString);
            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?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AshkanV
      wrote on last edited by
      #2

      Hello
      I had the same problem. It is looks like that Qt currently only supports "Minimal Conformance" and yet does not support optional XQuery features as it is described here:

      QXMLQuery Features and Conformance:

      XQuery 1.0
      
      Qt XML Patterns aims at being a conformant XQuery processor. It adheres to Minimal Conformance and supports the Serialization Feature and the Full Axis Feature. Qt XML Patterns currently passes 97% of the tests in the XML Query Test Suite. Areas where conformance may be questionable and where behavior may be changed in future releases include:
      
      Some corner cases involving namespaces and element constructors are incorrect.
      XPath is a subset of XQuery and the implementation of Qt XML Patterns uses XPath 2.0 with XQuery 1.0.
      
      The specifications discusses conformance further: XQuery 1.0: An XML Query Language. W3C's XQuery testing effort can be of interest as well, XML Query Test Suite.
      
      Currently fn:collection() does not access any data set, and there is no API for providing data through the collection. As a result, evaluating fn:collection() returns the empty sequence. We intend to provide functionality for this in a future release of Qt.
      
      Only queries encoded in UTF-8 are supported.
      

      And here is the relation of XQuery update with "Minimal Conformance"

      So I guess this feature is not included in the current version of QXMLQuery

      Instead it is possible to use QDomDocument

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved