title: Preventing duplicate element access when reading an XML using LINQ
body: <p>I got an XML that I'm trying to parse using LINQ to XML and convert it to an anonymous list of objects. To do so, I come up with the following code snippet:</p>
  
  <pre><code>var res = doc
              .Root
              .Elements("Record")
              .Elements("Term")
              .Select(term =&gt; new
              {
                  LanguageCode = term.Attribute("languageCode").Value,
                  ConceptNumber = Convert.ToInt32(term.Attribute("conceptNumber").Value),
                  IsHidden = Convert.ToBoolean(term.Attribute("hidden").Value),
                  Label = term.Value,
  
                  InputDate = DateTime.Parse(term.Parent.Element("InputDate").Value),
                  LastUpdate = DateTime.Parse(term.Parent.Element("LastUpdated").Value)
              }).ToList();
  </code></pre>
  
  <p>Please pay attention to the InputDate &amp; LastUpdate section. As you see, I've to access the <strong>parent node</strong> (say, term.Parent) so that I can access those 2 elements and this looks messy to me. Is there any way to declare term.Parent once and using it over and over again to extract those properties? </p>
  
  <p>Here's an excerpt of the XML I'm trying to read:</p>
  
  <pre><code>&lt;Record&gt;
    &lt;Term  languageCode="Prs" conceptNumber="10" hidden="False"&gt;Whatever&lt;/Term&gt;
    &lt;Status&gt;Approved&lt;/Status&gt;
    &lt;Frequency&gt;0&lt;/Frequency&gt;
    &lt;InputDate&gt;12/30/1899&lt;/InputDate&gt;
    &lt;LastUpdate&gt;10/25/2009&lt;/LastUpdate&gt;
  &lt;/Record&gt;
  </code></pre>
  
  <p>Thank you</p>