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 and XPath expression
Forum Updated to NodeBB v4.3 + New Features

QXmlQuery and XPath expression

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 3.4k 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.
  • R Offline
    R Offline
    redlars
    wrote on 6 Dec 2012, 12:13 last edited by
    #1

    Hello,

    How can I use QXmlQuery to execute an XPath expression?

    Here is some test code that compiles but does not work;

    @
    #include <QDomDocument>
    #include <QXmlQuery>
    #include <QFile>
    #include <QDebug>

    int main(int argc, char *argv[])
    {
    // Test code
    QFile file("Books.xml");
    file.open(QFile::ReadOnly);

    QXmlQuery query(QXmlQuery::XPath20);
    query.setFocus(&file);
    query.setQuery("//Book");
    bool validQuery = query.isValid();
    qDebug() << "QXmlQuery::isValid: " << validQuery;
    
    QStringList results;
    query.evaluateTo(&results);
    int count = results.count();
    qDebug() << "QStringList::Count: " << count;
    
    return 0;
    

    }
    @

    Books.xml looks like this;
    @
    <?xml version="1.0" encoding="utf-8"?>
    <Books>
    <Book>abc</Book>
    <Book>def</Book>
    <Book>ghi</Book>
    </Books>
    @

    According to QXmlQuery the query is valid but the result is always 0. Have tried various combinations of the query but nothing seems to work.

    The XPath expression works when testing it here: http://www.bit-101.com/xpath/

    Appreciate some help.

    1 Reply Last reply
    0

    1/1

    6 Dec 2012, 12:13

    • Login

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