Tuesday, December 14, 2010

Read XML File Node Wise using with xml DocumentElement And display on label


XMl FILE Strecture
<?xml version="1.0" encoding="utf-8" ?>
<adminModules>
<Module id="1" parentid="0" url="javascript:void(0);" title="Locator" real="false" />
</adminModules>
===================
using System.Xml;
string strFileName = Server.MapPath("~/Modules/ModuleMenu/AdminModules.xml");
XmlDocument oXmlDoc = new XmlDocument();
try
{
oXmlDoc.Load(strFileName);
}
catch (Exception ex)
{
lblMessage.Text ="Error: " + ex.Message;
}
XmlNode oNode = oXmlDoc.DocumentElement;
lblMessage.Text += "Node Name: " + oNode.Name;
XmlNodeList oNodeList = oNode.SelectNodes("/adminModules/Module/@title");
lblMessage.Text += "NodeList count=" + oNodeList.Count;
for (int x = 0; x < oNodeList.Count; x++)
{
lblMessage.Text += "NodeList Item#" + x + " " + oNodeList.Item(x).InnerText;
}

No comments:

Post a Comment