Results 1 to 2 of 2

Thread: QXmlSerializer, getting attribute and value from serializer

  1. #1
    Join Date
    Mar 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QXmlSerializer, getting attribute and value from serializer

    Hi everyone,
    I am using XQuery to grab a node from an XML document, everything works fine up till this point. I don't know what to do next.

    Problem description:
    I need to grab the attribute and the value from a single node that looks like this

    Qt Code:
    1. <strong class="class1">0.0376</strong>
    To copy to clipboard, switch view to plain text mode 

    to get this node I used

    Qt Code:
    1. QString xq = "doc('%1')";
    2. QXmlQuery queryxml;
    3. queryxml.setQuery(xq.arg(query));
    4. QByteArray output;
    5. QBuffer buffer(&output);
    6. buffer.open(QIODevice::WriteOnly);
    7.  
    8. QXmlSerializer serializer(queryxml, &buffer);
    9.  
    10. if (queryxml.isValid()) {
    11. queryxml.evaluateTo(&serializer);
    12.  
    13. qDebug() << "output: " << output;
    14. }
    To copy to clipboard, switch view to plain text mode 
    The reason I need to get the attribute is that class name will sometimes be "class2" and depending on that I need to do different things with the 0.0376 value.

    http://doc.trolltech.com/snapshot/qx...odelindex.html suggested to use an XML receiver to get attributes, names and child nodes, so I did that, but have no idea how to proceed and haven't seen any examples of this.
    So my question is: How to get the attribute and value of the node using either code above or other code that uses XQuery;
    Thanks,
    josh

  2. #2
    Join Date
    Aug 2009
    Posts
    1
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QXmlSerializer, getting attribute and value from serializer

    it is easy just put "@" befor name of attribute
    like this

    Qt Code:
    1. QXmlQuery query;
    2. query.setQuery("doc('index.html')/html/body/@onload"); // getting onload event of html document
    To copy to clipboard, switch view to plain text mode 

    for value you need
    Qt Code:
    1. QString QDomElement::text () const
    To copy to clipboard, switch view to plain text mode 
    Last edited by ihope; 12th August 2009 at 01:15.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.