LinQ to XML

Using LinQ to XML its very easy to query the Xml files and traverse through the nodes and elements.
Here is one simple exaple to read the configuration XML file

bellow is my simple XML configuration file



CPADCE008
CPADCE008VM1
CPADCE044
CPADCE044VM4
20100504



Then here is the simple class to load the XML file

class ConfigElements
{
public string ServerMain { get; set; }
public string ServerVM { get; set; }
public string ClientMain { get; set; }
public string ClientVM { get; set; }
public string LatestBuild { get; set; }

public ConfigElements(XElement xElement)
{
ServerMain = xElement.Element("ServerMain").Value;
ServerVM = xElement.Element("ServerVM").Value;
ClientMain = xElement.Element("ClientMain").Value;
ClientVM = xElement.Element("ClientVM").Value;
LatestBuild = xElement.Element("LatestBuild").Value;
}

public ConfigElements(string ID)
{
XDocument doc = XDocument.Load("XMLFile2.xml");

var query = from xElem in doc.Descendants("Automation")
where xElem.Attribute("ID").Value ==ID
select new ConfigElements(xElem);

}
}


By creating the object of this class we will get all the reqired nodes

ConfigElements objConfigElements = new ConfigElements("1");
//pass here the Id of the requied values
string s= objConfigElements.ServerMain;
string t = objConfigElements.ServerVM;
string u = objConfigElements.ClientMain;
string v = objConfigElements.ClientVM;
string w = objConfigElements.LatestBuild;

: