locked
XLINQ + OrderBy Clause RRS feed

Answers

  • Try the following:

     

            static void Main() {
                XDocument d = XDocument.Parse(@"
    <Feeds>
        <Feed>
            <Name>ScottGu Blog</Name>
            <Created>2007-08-04</Created>
        </Feed>
        <Feed>
            <Name>Weblogs.ASP.NET Main Feed</Name>
            <Created>2007-08-06</Created>
        </Feed>
        <Feed>
            <Name>Bozo Blog</Name>
            <Created>2007-08-05</Created>
        </Feed>
    </Feeds>
    ");
                var q = from feed in d.Descendants("Feed")
                        orderby (DateTime)feed.Element("Created") ascending
                        select feed;
                foreach (XElement feed in q)
                    Console.WriteLine(feed);
            }

     

    Ion
    Wednesday, September 12, 2007 9:40 PM

All replies

  • Try the following:

     

            static void Main() {
                XDocument d = XDocument.Parse(@"
    <Feeds>
        <Feed>
            <Name>ScottGu Blog</Name>
            <Created>2007-08-04</Created>
        </Feed>
        <Feed>
            <Name>Weblogs.ASP.NET Main Feed</Name>
            <Created>2007-08-06</Created>
        </Feed>
        <Feed>
            <Name>Bozo Blog</Name>
            <Created>2007-08-05</Created>
        </Feed>
    </Feeds>
    ");
                var q = from feed in d.Descendants("Feed")
                        orderby (DateTime)feed.Element("Created") ascending
                        select feed;
                foreach (XElement feed in q)
                    Console.WriteLine(feed);
            }

     

    Ion
    Wednesday, September 12, 2007 9:40 PM
  • Doh!

     

    I was using the feed.Descendents instead of feed.Element.  Thank you so much!

     

    Bill

     

    Wednesday, September 12, 2007 11:27 PM