You can do this by different ways..
Actual what is the type of above mentioned XML,
is it in String type or XmlDocument type..?
And To Which this Xml data is to convert? object type or you want to select each individual tags..?
1)If the above file is in String type, then it is better to convert that to Object type,
Create a class called Book
and create properties to that class with the same name in the each tag ex:BookName
Called Xml Deserialization
XML Deserialization:
Deserialization is the reverse process. We will load in an xml, pass the data to the deserializer and it produce an instance of the class populated with the data.
XML Serialization:
XML Serialization is the process of saving class member data into an XML. Only public classes and public properties and fields can be serialised – methods and private members are not serialized and cannot be deserialized. Private classes cannot be serialized and will result in a compilation error.
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public class Book
{
public string BookName { get; set; }
public string ReleaseYear { get; set; }
public string Publication { get; set; }
}
public List<Book> ConvertXmlToList()
{
List<Book> list = new List<Book>();
using (var sr = new StreamReader(@"c:\test.xml"))
{
var deserializer = new XmlSerializer(typeof(List<Book>));
list = (List<Book>)deserializer.Deserialize(sr);
}
return list;
}