I have an xml from which I am trying to extract some information through LINQ query.
The format of the xml file looks like the following:
hi i think this is what you expect.
List lstXElements = new List();
lstXElements.AddRange(GetDescendants("NextItem"));
lstXElements.AddRange(GetDescendants("PreviousItem"));
List lstExtract = new List();
foreach (XElement objElement in lstXElements)
{
Extract objExtract = new Extract();
objExtract._id = Convert.ToInt32(objElement.Attribute("id").Value);
objExtract.name = (objElement.Name).LocalName;
lstExtract.Add(objExtract);
}
List GetDescendants(string strDescentName)
{
return ((XDocument.Load(Server.MapPath("XMLFile1.xml"))
.Descendants(strDescentName))
).ToList();
}