From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, STOX_REPLY_TYPE autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,cd3701d5ec722b08 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe09.iad.POSTED!92f42029!not-for-mail From: "Steve D" Newsgroups: comp.lang.ada References: <9b330aae-2c83-4d1c-995b-192425cd1c52@m11g2000vbl.googlegroups.com> In-Reply-To: <9b330aae-2c83-4d1c-995b-192425cd1c52@m11g2000vbl.googlegroups.com> Subject: Re: Lambda expressions? LINQ? MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Windows Mail 6.0.6001.18000 X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6001.18049 Message-ID: X-Complaints-To: abuse@teranews.com NNTP-Posting-Date: Sat, 19 Sep 2009 02:33:54 UTC Organization: TeraNews.com Date: Fri, 18 Sep 2009 19:33:51 -0700 Xref: g2news2.google.com comp.lang.ada:8389 Date: 2009-09-18T19:33:51-07:00 List-Id: >"sjw" wrote in message >news:9b330aae-2c83-4d1c-995b-192425cd1c52@m11g2000vbl.googlegroups.com... >On Sep 18, 2:59 am, "Steve D" wrote: >> "Jeffrey R. Carter" wrote in >> messagenews:h8qf72$jv2$2@news.tornevall.net... >> >> > Steve D wrote: >> >> >> Using LINQ and the .NET framework I was able to query an XML document >> >> for >> >> all elements with a given element name, select an attribute with a >>> >> specific name, split the content of the attribute (a comma separated >>> >> list >> >> of strings) into it's individual strings and return an array of unique >> >> elements... in one line of source code. ... Wow! >> >> > Sounds like a write-only language to me. >> >> Oh, so you are familiar with LINQ and find that you cannot make queries >> that >> are readable? >> My experience is not the same. > >It would certainly be interesting to see this one-liner (or even an >approximation to it!). As Martin guessed it is one statement spread over a few lines. string[] names = xDoc.Descendants("Layer0Message") .SelectMany(node => node.Attribute("To").Value.Split(' ',',').Where( st => st.Length > 0 )) .Distinct().OrderBy(n=>n).ToArray(); There is an alternate way of formatting the query... more like SQL, but I prefer the version that uses the dot notation. Here's a small chunk of the XML data it is reading: 63 BF F4 C0 C7 3C 02 00 C3 4F 4F 14 88 3D 5A C2 32 BD Oh, and by the way. LINQ isn't just for XML. You can do queries on arrays, lists, etc. For example if you have an array of records you can do a query to select all of the records with a field that has a particular value. It's cool. I just wish my favoriate language had this feature. Regards, Steve