using System.Xml;
using System.Linq;
using System.Xml.Linq;
Response.Write("<b>Using XmlTextReader</b><br /><br />");
using (XmlTextReader reader = new XmlTextReader(Server.MapPath("Country.xml")))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Text)
{
Response.Write(reader.Value + "<br />");
}
}
}
Response.Write("<br /><b>Using XmlReader</b><br /><br />");
using (XmlReader reader = XmlReader.Create(Server.MapPath("Country.xml")))
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Text)
{
Response.Write(reader.Value + "<br />");
}
}
}
Response.Write("<br /><b>Using XmlNodeReader</b><br /><br />");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("Country.xml"));
XmlNodeReader nodeReader = new XmlNodeReader(xmlDoc);
while (nodeReader.Read())
{
if (nodeReader.NodeType == XmlNodeType.Text)
{
Response.Write(nodeReader.Value + "<br />");
}
}
xmlDoc = null; nodeReader = null;
Response.Write("<br /><b>Using XDocument</b><br /><br />");
XDocument xDoc = XDocument.Load(Server.MapPath("Country.xml"));
var xmlAtt = from att in xDoc.Elements("CountryList").Elements("Name")
select att;
foreach (var record in xmlAtt)
{
Response.Write(record.Value + "<br />");
}
xDoc = null; xmlAtt = null;