How to get the immediate child elements of the root element using C # and XML?

advertisements
 <Document>
    <Heading1>
         <text>Heading Title</text>
         <para>para1</para>
         <para>para2</para>
         <para>para3</para>
     </Heading1>
    <Heading1>
         <text>2nd Heading Title</text>
         <para>para4</para>
         <para>para5</para>
         <para>para6</para>
         <Heading2>
              <text>3rd Heading Title</text>
              <para>para4</para>
              <para>para5</para>
         </Heading2>
     </Heading1>
 </Document>

This is XML Document. Now, i want to parse this XML file using C# (4.0). Here, I want to get all the Heading1 elements without using that element name in my program. For example, don't use document.GetElementsByTagName("Heading1");. How i get it. Guide me get out of this issue.

Thanks & Regards.


Using LINQ to XML, you can do:

var headings = yourXDocument.Root.Elements();

Using Nodes() instead of Elements() will also return text nodes and comments, which is apparently not what you want.