title: XML parsing to get a particular tag value in a list of XElement
body: <p>I have below XML and c# code.
  I want to get the list of values like <code>333,382</code> in a list present in <code>&lt;Event &gt;</code>tag.</p>
  <p>However with below code i am getting the list of whole Event tag like<code>{ Event = &quot;333&quot; },{ Event = &quot;382&quot; }</code></p>
  <p><a href="https://i.stack.imgur.com/BYCmW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BYCmW.png" alt="enter image description here" /></a></p>
  <p>I can code few more logic to get only the numeric part out of it but for code efficiency its better to get the required value like <code>333,382</code> in eventList itself through LINQ.</p>
  <p>Can somebody please help on it ? Thanks in advance.</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text.RegularExpressions;
  using System.Xml.Linq;
  
  namespace ConsoleApp1
  {
      class Program
      {
          static void Main(string[] args)
          {
              string eventListXML= @&quot;&lt;XYZ&gt;
                                      &lt;Task&gt;
                                          &lt;ABC&gt;
                                              &lt;EvtLogResponse&gt;
                                                  &lt;LogInfo&gt;
                                                      &lt;CommID&gt;8&lt;/CommID&gt;
                                                      &lt;UserId&gt;2&lt;/UserId&gt;
                                                      &lt;Date&gt;10/09/2020&lt;/Date&gt;
                                                      &lt;Time&gt;06:24:01 PM&lt;/Time&gt;
                                                  &lt;/LogInfo&gt;
                                                  &lt;EventLogAllRes&gt;
                                                      &lt;EventOrRestore&gt;E&lt;/EventOrRestore&gt;
                                                      &lt;Event&gt;333&lt;/Event&gt;
                                                  &lt;/EventLogAllRes&gt;
                                                  &lt;EventLogAllRes&gt;
                                                      &lt;EventOrRestore&gt;E&lt;/EventOrRestore&gt;
                                                      &lt;Event&gt;382&lt;/Event&gt;
                                                  &lt;/EventLogAllRes&gt;
                                                  &lt;FilePath&gt;C:\Windows\test.txt&lt;/FilePath&gt;
                                              &lt;/EvtLogResponse&gt;
                                              &lt;UserID&gt;1&lt;/UserID&gt;
                                          &lt;/ABC&gt;
                                      &lt;/Task&gt;
                                  &lt;/XYZ&gt;&quot;;
  
              XDocument xDoc = XDocument.Parse(eventListXML);
              XElement Xele = xDoc.Element(&quot;XYZ&quot;).Element(&quot;Task&quot;).Element(&quot;ABC&quot;).Element(&quot;EvtLogResponse&quot;);
              List&lt;XElement&gt; Logs = Xele.Elements(&quot;EventLogAllRes&quot;).ToList&lt;XElement&gt;();
  
  
              var eventList = (from Event in Logs.Descendants(&quot;Event&quot;)
                               select new
                               {
                                   Event = Event.Value
  
                               }).ToList();
               
          }
      }
  }
  </code></pre>