-
XML : Data filtering
Hi,
I have an xml like below
[CODE]
<channel>
<item>
<type> On </type>
<title> item1 <</title>
<imagePath> http://... </imagePath>
</item>
<item>
<type> On </type>
<title> item2 <</title>
<imagePath> http://... </imagePath>
</item>
<item>
<type> Off </type>
<title> item3 <</title>
<imagePath> http://... </imagePath>
</item>
<item>
<type> Off </type>
<title> item4 <</title>
<imagePath> http://... </imagePath>
</item>
<item>
<type> On </type>
<title> item5 <</title>
<imagePath> http://... </imagePath>
</item>
</channel>
[/CODE]
I am using [B]XmlListModel[/B] to parse the XML and display the xml content in a delegate like below
[CODE]
XmlModel {id: feedModel}
ListView {
id: list
width: mainwindow.width ; height: mainwindow.height
model: feedModel
delegate: NewsDelegate {}
}
[/CODE]
With this above code I can perfectly display all the items in the listview. Now what I am trying to do is, I just want to display the items that are having [B]On[/B] in there [B]<type>[/B] tag.
I put a check in the delegate file and can display item that are having [B]On[/B] in there [B]<type>[/B] tag, with the below code
[CODE]
Image {
id: thumb
source: if(type == "On"){imagePath} // display only one category item
x: 1; y: 1; smooth: true
}
[/CODE]
But when I do this it displays the 1st, 2nd and the 5th items leaving the 3rd and 4th place blank (empty). I mean in the listview the 3rd and 4th place remains empty, and the 5th item doesn't comes after the 2nd item.
Any idea why this is happening or how can I resolve this. please suggest me
-
Re: XML : Data filtering
I can guess why this happens, but not how to fix it.
According to the [URL="http://doc.qt.nokia.com/4.7/qml-xmllistmodel.html#details"]documentation[/URL] the model creates an item for every element matching the XPATH in the "quer"y statement. You haven't declared a query so you're getting all elements - creating an item for each. When you set the source of the image to nothing you still get the item.
I'm not sure of the solution because I don't know enough about XPATH. I'd see if there is any way in XPATH to look at the content of type and then use this to specify the parent items. If not, next best guess would be to try filtering the list to remove any items which don't match your requirement as a post process. Lastly, you might try setting these items to have zero height or to be invisible.
Good luck. Please post your end solution here.
See this bit:
-
Re: XML : Data filtering
Further to my last response, try the advice in the query element using a query similar to that defined here: [url]http://stackoverflow.com/questions/472966/xpath-multiple-element-filters[/url]
-
Re: XML : Data filtering
[QUOTE=hamishwillee;854731]I can guess why this happens, but not how to fix it.
According to the [URL="http://doc.qt.nokia.com/4.7/qml-xmllistmodel.html#details"]documentation[/URL] the model creates an item for every element matching the XPATH in the "quer"y statement. You haven't declared a query so you're getting all elements - creating an item for each. When you set the source of the image to nothing you still get the item.
I'm not sure of the solution because I don't know enough about XPATH. I'd see if there is any way in XPATH to look at the content of type and then use this to specify the parent items. If not, next best guess would be to try filtering the list to remove any items which don't match your requirement as a post process. Lastly, you might try setting these items to have zero height or to be invisible.
Good luck. Please post your end solution here.
See this bit:[/QUOTE]
Thank you for your reply, it clears me a lot. You are right. My [B]query: "/rss/channel/item"[/B] creates a model for each [B]<item>[/B] tag, and even if I don't display any image it ocupies the blank space. Is there any way I could put a check in the [B]XmlListModel[/B] so that it can only reads those item which has the [B]<type>[/B] tag [B]On[/B], or its can't happen as because the query reads from item to item.
Even I tried to make the unwanted item to be Invisible, but it invisible all the items along with the one i am looking for.
i use the the [B]visible:[/B]
here is the code
[CODE]
Image {
id: thumb
source: if(type == "On"){imagePath} // display only one category item
x: 1; y: 1; smooth: true
}
[/CODE]
could you please help me to put a code how can I invisible the items that are not [B]On[/B], so the I can see only the [B]On [/B] items continuously without any blank space.
-
Re: XML : Data filtering
[QUOTE=hamishwillee;854737]Further to my last response, try the advice in the query element using a query similar to that defined here: [url]http://stackoverflow.com/questions/472966/xpath-multiple-element-filters[/url][/QUOTE]
You are great , this solve this issue. Here is my query [B]query: "/rss/channel/item[type='On']"[/B]
Thank you Hamish :)