title: Extracting XElement children and grandchildren by name
body: <p>I have an XElement (myParent) containing multiple levels of children that I wish to extract data from.  The elements of interest are at known locations in the parent.</p>
  
  <p>I understand that I am able to get a child element by:</p>
  
  <pre><code>myParent.Element(childName);
  </code></pre>
  
  <p>or</p>
  
  <pre><code>myParent.Element(level1).Element(childName);
  </code></pre>
  
  <p>I am having trouble figuring out how to do this if I want to loop through an array offor a list of elements that are at different levels, and looping through the list.  For instance, I am interested in getting the following set of elements:</p>
  
  <pre><code>myParent.Element("FieldOutputs").Element("Capacity");
  myParent.Element("EngOutputs").Element("Performance")
  myParent.Element("EngOutputs").Element("Unit").Element("Efficiency")
  </code></pre>
  
  <p>How can I define these locations in an array so that I can simply loop through the array?</p>
  
  <p>i.e. </p>
  
  <pre><code>string[] myStringArray = {"FieldOutputs.Capacity", "EngOutputs.Performance", "EngOutputs.Unit.Efficiency"};
  
  for (int i=0; i&lt; myArray.Count(); i++)
  {
      XElement myElement = myParent.Element(myStringArray);
  }
  </code></pre>
  
  <p>I understand that the method above does not work, but just wanted to show effectively what I am trying to achieve.</p>
  
  <p>Any feedback is appreciated.</p>
  
  <p>Thank you,
  Justin</p>