Results 1 to 5 of 5

Thread: Retrieving a list from a XML to LINQ query

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Question Retrieving a list from a XML to LINQ query

    vb.net Code:
    1. public class FeedDefinition
    2.     {
    3.         public string Name { get; set; }
    4.         public string Url { get; set; }
    5.     }
    6.  
    7.         public List<FeedDefinition> LoadFeeds(string path)
    8.         {
    9.             XDocument feedXML = XDocument.Load(path);
    10.  
    11.             var feeds = from feed in feedXML.Descendants("Feed")
    12.                         select new FeedDefinition
    13.                         {
    14.                             Name = feed.Element("Name").Value,
    15.                             Url = feed.Element("Url").Value
    16.                         };
    17.  
    18.             return feeds.ToList();
    19.         }

    This code returns a list with each element queried from the feed, how does it "work"? In other words, first the names and then the Urls? How?

    Thanks in advance.

    I've attached a picture of the xml file model.

    It was obtained from here.
    Attached Images Attached Images  
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  2. #2
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: Retrieving a list from a XML to LINQ query

    hey,
    i didn't understand what you actually need
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: Retrieving a list from a XML to LINQ query

    In the 18th line of the code I posted, it says:

    Code:
    return feeds.ToList();
    How is the content organized in this list? I mean, seeing that the class FeedDefinition has two strings: Name and Url; is the information recovered from the query stored in one single list or does it create two individual lists for each public string (Name and Url).

    In other words, what does ToList() mean? I know it creates a generic list, but is it for each item or it contains the information queried from each string?
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  4. #4
    Frenzied Member avrail's Avatar
    Join Date
    Mar 2006
    Location
    Egypt, Cairo
    Posts
    1,221

    Re: Retrieving a list from a XML to LINQ query

    hey,
    actually your list comes from feeds and this is a list of items
    but your item divided into Name and Url
    as i can see your item here is FeedDefinition
    and FeedDefinition is an object contains of 2 strings, so you have a got a list of FeedDefinitions
    You Don't Have to Rate Me.
    I'm Not a Civilized Man I'm the Civilization it self
    White or Black, Living or Dieing and 0 or 1 that's MY life
    iam an Object in Object Oriented Life
    my blog : http://refateid.blogspot.com/
    twitter :@avrail
    010011000111010101110110001000000100110101111001001000000101000001100011

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: Retrieving a list from a XML to LINQ query

    Thanks for that. The reason I asked how each item in the list is stored it is because I want to know how to be able to get a specific item from that list, i.e Names. How would I go to do that?
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

Posting Permissions

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



Click Here to Expand Forum to Full Width