Saturday, June 2, 2012

Read Xml File in .net



Public Void GetXmlData()
{
XmlDocument doc = new XmlDocument();
doc.Load("http://www.kirupa.com/net/files/sampleXML.xml");
 
XmlNodeList bookList = doc.GetElementsByTagName("Book");
 
foreach (XmlNode node in bookList)
{

XmlElement bookElement = (XmlElement) node;
 
string title = bookElement.GetElementsByTagName("title")[0].InnerText;
string author = bookElement.GetElementsByTagName("author")[0].InnerText;
string isbn = "";
 
if (bookElement.HasAttributes)
{
isbn = bookElement.Attributes["ISBN"].InnerText;
}
 
Console.WriteLine("{0} ({1}) is written by {2}\n"titleisbnauthor);

}
}

No comments:

Post a Comment