×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,348

    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>
    I am using XmlListModel 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 {}
        }
    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 On in there <type> tag.
    I put a check in the delegate file and can display item that are having On in there <type> 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
                    }
    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
    Last edited by somnathbanik; 2011-08-02 at 07:39. Reason: added

  2. #2
    Super Contributor
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    2,578

    Re: XML : Data filtering

    I can guess why this happens, but not how to fix it.

    According to the documentation 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:

  3. #3
    Super Contributor
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    2,578

    Re: XML : Data filtering

    Further to my last response, try the advice in the query element using a query similar to that defined here: http://stackoverflow.com/questions/4...lement-filters

  4. #4
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,348

    Re: XML : Data filtering

    Quote Originally Posted by hamishwillee View Post
    I can guess why this happens, but not how to fix it.

    According to the documentation 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:
    Thank you for your reply, it clears me a lot. You are right. My query: "/rss/channel/item" creates a model for each <item> 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 XmlListModel so that it can only reads those item which has the <type> tag On, 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 visible:
    here is the code
    Code:
     Image {
                        id: thumb
                       source: if(type == "On"){imagePath}   // display only one  category item
                        x: 1; y: 1; smooth: true
                    }
    could you please help me to put a code how can I invisible the items that are not On, so the I can see only the On items continuously without any blank space.
    Last edited by somnathbanik; 2011-08-02 at 09:02. Reason: added

  5. #5
    Nokia Developer Champion
    Join Date
    Dec 2008
    Posts
    2,348

    Re: XML : Data filtering

    Quote Originally Posted by hamishwillee View Post
    Further to my last response, try the advice in the query element using a query similar to that defined here: http://stackoverflow.com/questions/4...lement-filters
    You are great , this solve this issue. Here is my query query: "/rss/channel/item[type='On']"


    Thank you Hamish
    Last edited by somnathbanik; 2011-08-02 at 09:15. Reason: added

Similar Threads

  1. XMLHttpRequest for xml file data
    By oldfield in forum Geolocation and Navigation
    Replies: 1
    Last Post: 2010-03-17, 05:32
  2. FILESELECTIONDIALOG not filtering the data
    By not_dying in forum Symbian C++
    Replies: 2
    Last Post: 2010-02-12, 09:25
  3. XML data sending problem
    By amit04.kumar in forum Symbian C++
    Replies: 10
    Last Post: 2009-10-26, 15:36
  4. Filtering data from accelerometer
    By BAM8 in forum Python
    Replies: 7
    Last Post: 2009-08-25, 12:22
  5. Problem in loading xml data
    By mehraj123 in forum Symbian Web Runtime
    Replies: 1
    Last Post: 2009-01-24, 12:43

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •