Tuesday, November 2, 2010

READ XML DOCUMENT IN ASP.NET


using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.IO;
using System.Xml;


Stream objStream = null;

WebRequest wrGETURL;
wrGETURL = WebRequest.Create(data);

try
{

objStream = wrGETURL.GetResponse().GetResponseStream();

}
catch (Exception ex)
{
ex.ToString();
}

StreamReader sr = new StreamReader(objStream);
string dr = sr.ReadToEnd();


XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(dr);


foreach (XmlNode nod in xmlDoc.DocumentElement)
{

foreach(XmlAttribute attr in nod.Attributes)
{

string na = attr.Name;
string v = attr.Value;

if (na.Equals("Limit"))
{
LblLimitName.Text = na;
LblLimitValue.Text = v;
}
else if(na.Equals("Used"))
{
LblUsedName.Text = na;
LblUsedValue.Text = v;
}

}




}




sr.Close();
objStream.Close();


0 comments:

Post a Comment