Tuesday, November 22, 2011

Reading an XML file

Easy way of reading an xml file without linq or xpath

XmlDocument comment = new XmlDocument();
//full path. use .Load for URL
comment.LoadXml(File.ReadAllText(myfile.FullName));
XmlNodeList xnList = comment.SelectNodes("/RootNode");
foreach (XmlNode xn in xnList)
{
title = xn["Title"].InnerText;
description = xn["Content"].InnerText;
}

No comments:

Post a Comment