I have an XML file that I want to access in an Windows Phone 7 and Silverlight application. Th XML file is on a webserver, and I want to access it through http://www.mydomain.com/data/this_is_my_file.xml.
How do I use this URL to load the XML file into an XDocument?
You can use
WebClient
orHttpWebRequest
to download (asynchronously) and parse the response. One of the simplest approach to download and parse XML from the web is below -xmlUrl
is the path to the XML file on the web.XmlItem
is a class like so -You need to note that you may encounter cross-thread exception if you are updating an observable collection. In the above example, XmlItems is a
List<XmlItem>
. However, if you wish to add the XMLItem's to an observable collection, use this piece of code instead -An alternative approach is to use
HttpWebRequest
. You can read about this approach here and use the code in the sample.HTH, indyfromoz