Q:

How to Select/Iterate through multiple elements with a specific attribute XML?

Using C# - Microsoft Visual Studio 2015 - using System.Xml.Linq
I am trying to parse through an XML with the format below. The objective of the code is to look through all messages, and see which ones are missing translations for a given ID, and write those messages out to a new XML for each ID (in a sense, filling in the gaps that are missing).
Example below: There are 4 ID's (A,B,C,D). Message 1 is missing D, Message 2 is missing B and C, and Message 3 is missing A, C, and D. So, a new XML document for ID A will include Message 3. For B, it will include Message 2. For C, it will include Messages 2 and 3. For D, it will include Messages 1 and 2.
<M Code="Message 1" Translate="Y">
<ID="A"><![Translation A]></Lang>
<ID="B"><![Translation B]></ID>
<ID="C"><![Translation C]></ID>

</M>
<M Code="Message 2" Translate="Y">
<ID="A"><![Translation A]></ID>
<ID="D"><![Translation D]></ID>

</M>
 <M Code="Message 3" Translate="Y">
<ID="B"><![Translation B]></ID>
 </M>

I currently iterate through a loop containing all 4 IDs (var id) with the following:
IEnumerable < XElement > forTrans = from el in UIWxml.Root.Elements("M")where (string)el.Attribute("Translate").Value == "Y" & (string)el.Elements().First().Attribute("ID").Value.ToUpper() != id

This code successfully performs the desired task, but it ONLY works on the first ID in each message - it does not check all instances (in the example, this would only mean it only checks ID A in Messages 1 and 2, and ID D in Message 3). I have been trying to mess around with this line, where I believe the problem is: 
(string)el.Elements().First().Attribute("ID").Value.ToUpper() != id 
I am looking for a solution that allows me to check all elements where the attribute ID != one of the hard-coded IDs (in the example, I would like it to look through all 3 IDs in M1, 2 IDs in M2, etc). Any help would be appreciated. Thank you! 

A:

Try using 
IEnumerable <XElement> forTrans = 
  FROM el in UIWxml.Root.Elements("M")
  WHERE (string)el.Attribute("Translate").Value == "Y" & 
        el.Elements().All(
          c=> c.Attribute("ID").Value.ToUpper() != id
        )

