+1  A: 

Your XML looks a little bit malformed due to the . before each tag name; I therefore sanitized your XML code by removing the .s, and made a solution based on the following XML code:

<SECTIONS> 
    <SECTION ID ="1" NAME="System Health" CONTROL-TYPE="Button" LINK="http://www.google.co.in/"&gt;
        <DATAITEMS> </DATAITEMS> 
    </SECTION> 
</SECTIONS>

Thanks to the sanitized XML code, you now can use the following code snippet to achieve what you want (don't forget the using directive using System.Xml.Linq;):

XDocument doc = XDocument.Parse("<SECTIONS><SECTION ID =\"1\" NAME=\"System Health\" CONTROL-TYPE=\"Button\" LINK=\"http://www.google.co.in/\"&gt;&lt;DATAITEMS&gt;&lt;/DATAITEMS&gt;&lt;/SECTION&gt;&lt;/SECTIONS&gt;");
var query = from item in doc.Descendants("SECTIONS").Descendants("SECTION")
            select new { 
                Name = (string)item.Attribute("NAME"),
                Id = (string)item.Attribute("ID"),
                ControlType = (string)item.Attribute("CONTROL-TYPE"),
                Link = (string)item.Attribute("LINK")
            };

(Sidenote: You can load your XML code directly from a file (e.g. file.xml), too, by defining the doc variable as follows:

XDocument doc = XDocument.Load(@"C:\Path\To\file.xml");

)

The following code will print the value of each attribute:

foreach (var elem in query)
            System.Console.WriteLine(string.Format("{0}, {1}, {2}, {3}", elem.Id, elem.Name, elem.ControlType, elem.Link));

Console output:

1, System Health, Button, http://www.google.co.in/
Giu
oh.. that dot was given explicitly by me. cause this page cannot render content enclosed with <>
Lalit
You could remove the dots using a regular expression right before querying the XML with LINQ as follows (without touching the original XML code): `string xml = Regex.Replace("<.SECTIONS><.SECTION><./SECTION><./SECTIONS>", "<.", "<"); var doc = XDocument.Parse(xml);`. The resulting sanitized XML string will be `<SECTIONS><SECTION></SECTION></SECTIONS>`.
Giu
no no u r not getting me... this forum page is not support enclosed <>
Lalit
+1  A: 

As @Giu mentions, your XML is technically malformed with the . preceding each element name.

To get the names of the attributes available in SECTION:

string xmlData = "<SECTIONS> <SECTION ID =\"1\" NAME=\"System Health\" CONTROL-TYPE=\"Button\" LINK=\"http://www.google.co.in/\"&gt; <DATAITEMS> </DATAITEMS> </SECTION> </SECTIONS>";
XDocument doc = XDocument.Parse( xmlData );
//The above line could also be XDocument.Load( fileName ) if you wanted a file

IEnumerable<string> strings = doc.Descendants("SECTIONS")
                                 .Descendants("SECTION")
                                 .Attributes()
                                 .Select( a => a.Name.LocalName );

This will give you an enumerable containing ID, NAME, CONTROL-TYPE, and LINK.

However, if you want the values contained in them, I would use @Giu's answer.

Daniel Joseph