April 29, 2011

situ117 situ117
Lab Rat
31 posts

[Solved] Filtering data in XMLListModel

 

Hello,

I want to know how can we filter data in XMLListModel.

Let’s say I’ve following XML file:

  1. <root>
  2. <file>image1.jpeg<file>
  3. <file>tune.mp3<file>
  4. <file>image2.jpeg<file>
  5. </root>

and I want to fetch all file names which have “.jpeg” extension. XPath defines contains() function to compare strings; is it supported by QML ?

3 replies

April 30, 2011

Andre Andre
Robot Herder
6422 posts

I think so yes, but why don’t you just try and see?

April 30, 2011

situ117 situ117
Lab Rat
31 posts

Hi,

Thanks for your reply. I was making a mistake while writing XPath predicate. Following model works for me now.

  1. XmlListModel {
  2.     source: "mysource.xml"
  3.     query: "/root/file[contains(.,'jpeg')]"
  4.  
  5.     XmlRole { name: "name"; query: "string()" }
  6. }

April 30, 2011

Andre Andre
Robot Herder
6422 posts

Glad that it works for you, and thanks for reporting back!

 
  ‹‹ [SOLVED]Javascript used to remove specific ListElements (works but has one issue)      XmlListModel - Host requires authentication ››

You must log in to post a reply. Not a member yet? Register here!