How to read XML file with asp.net? I want to change the title for the xml file?

Posted by Gaddad under ASP.NET on 8/25/2009 | Views : 13016 | Status : [Member] | Replies : 1
How to read XML file with asp.net? I want to change the title for the xml file?

Thanks....




Responses

Posted by: Lakhangarg on: 8/25/2009 [Member] [Moderator] Silver

Up
0
Down
Hi Gaddad-
Below is the code to read the content of xml file

private void ReadXMLData(string SourceCountry, string DestCountry)

{
double Amount = 10;
string SourceCode = "";
double SourceCountryValue=0;
double DestCountryValue=0;
string DestCode = "";
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("Convertor.xml"));
XmlNodeList xmlList= xmlDoc.GetElementsByTagName("Country");
for (Int16 iCount = 0; iCount < xmlList.Count; iCount++)
{
if (xmlList.Item(iCount).Attributes.GetNamedItem("name").InnerText == SourceCountry)
{
SourceCountryValue = Convert.ToDouble(xmlList.Item(iCount).Attributes.GetNamedItem("value").InnerText);
SourceCode = xmlList.Item(iCount).Attributes.GetNamedItem("CurrencyCode").InnerText;
}
else if (xmlList.Item(iCount).Attributes.GetNamedItem("name").InnerText == DestCountry)
{
DestCountryValue = Convert.ToDouble(xmlList.Item(iCount).Attributes.GetNamedItem("value").InnerText);
DestCode = xmlList.Item(iCount).Attributes.GetNamedItem("CurrencyCode").InnerText;
}
}
Response.Write(Amount.ToString()+ " "+SourceCode +"=" +Convert.ToString(Amount * (DestCountryValue / SourceCountryValue)));
}


Please find the attached XML file used in the above code.

Thanks & Regards
Lakhan Pal Garg
http://lakhangarg.blogspot.com/
 Download source file

Gaddad, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response