Question : How to download an xml file in Silverlight application?


Hello,

please tell me how to Load an XML file either from project folder or from internet in a Silverlight application?
I have tried the following approaches:
1) I have followed Kirupa's tutorial on downloading an xml file, but it does not work. I am using Visual Studio 2010
and .NET 4 with C#.
The tutorial is at:
http://www.kirupa.com/blend_silverlight/loading_xml_sl2_pg1.htm
I cannot see the downloaded content of the xml file in the messagebox or in the HtmlPage.Window.Alert(xmlData);

2) I have also tried

XDocument doc = XDocument.Load("xmlFile.xml");
            MessageBox.Show(doc.ToString());

But the
 MessageBox.Show(doc.ToString());

does not appear.

Please tell me what I should do so that I can download an xml file as a string in my silverlight project so that I can manipulate it to display the result in my silverlight application.

This question comes after my previous question as I have realized that I might have to download the xml file for processing as the xml file is complicated and the images are not part of itemCollection; however, I am not sure.

Please suggest what I should do so that I can download an xml file in silverlight .net 4.0 (VS 2010 IDE with C#) as a string so that I can use LINQ as I believe that is the way to go, but the tutorial I have found, from Kirupa, does not work ( the HtmlPage.Window.Alert(xmlData); or MessageBox.Show(...) does not appear).

Answer : How to download an xml file in Silverlight application?

This is what you need to do....This is the code from one of the live project.

ClientInfoList is a class which contains all the properties that i am reading from the xml document.


List<ClientInfoData> clientInfoList;
XDocument doc = XDocument.Load(@"..\..\xml_files\clientinfo.xml");
clientInfoList = (from client in doc.Descendants("Client")
orderby client.Element("Name").Value
select new ClientInfoData
{
ClientId = client.Element("ClientId").Value,
EnergyAdvisor = client.Element("EnergyAdvisor").Value,
Name = client.Element("Name").Value,
City = client.Element("City").Value,
HomePhone = client.Element("HomePhone").Value,
Email = client.Element("Email").Value,
Visit = client.Element("Visit").Value,
Language = client.Element("Language").Value,
Province = client.Element("Province").Value,
StreetNumber = client.Element("StreetNumber").Value,
PostalCode = client.Element("PostalCode").Value,
}).ToList();

So you have all the dta from the xml doc.....If you wnat you can use any other loop to get the data from the xml doc.

If there is any other question, let me know.

Random Solutions  
 
programming4us programming4us