W8 Phone System.Xml.XmlException avec XmlReader

J’essaie de créer une application RSS pour Windows Phone 8, mais une erreur se produit chaque fois que j’essaie de télécharger le contenu RSS à l’aide d’un XmlReader.

using System.Xml.Linq; using System.Net; using System.ServiceModel.Syndication; XmlReaderSettings settings = new XmlReaderSettings(); settings.DtdProcessing = DtdProcessing.Ignore; XmlReader reader = XmlReader.Create(http://feeds.bbci.co.uk/news/business/rss.xml, settings); SyndicationFeed feed = SyndicationFeed.Load(reader); reader.Close(); 

L’erreur se trouve sur la ligne “XmlReader reader = XmlReader.Create ….” Le message d’erreur complet est:

Une première exception de type “System.Xml.XmlException” s’est produite dans System.Xml.ni.dll

Informations supplémentaires: Impossible d’ouvrir ‘ http://feeds.bbci.co.uk/news/business/rss.xml ‘. Le paramètre Uri doit être un chemin relatif du système de fichiers.

Merci de votre aide! 🙂

Vous obtenez cette erreur car elle attend un fichier dans LocalStorage pas une adresse Web. Donc, vous devez télécharger le fichier et le convertir comme suit:

 public MainPage() { // our web downloader WebClient downloader = new WebClient(); // our web address to download, notice the UriKind.Absolute Uri uri = new Uri("http://feeds.bbci.co.uk/news/business/rss.xml", UriKind.Absolute); // we need to wait for the file to download completely, so lets hook the DownloadComplete Event downloader.DownloadSsortingngCompleted += new DownloadSsortingngCompletedEventHandler(FileDownloadComplete); // start the download downloader.DownloadSsortingngAsync(uri); } // this event will fire if the download was successful void FileDownloadComplete(object sender, DownloadSsortingngCompletedEventArgs e) { // e.Result will contain the files byte for byte // your settings XmlReaderSettings settings = new XmlReaderSettings(); settings.DtdProcessing = DtdProcessing.Ignore; // create a memory stream for us to use from the bytes of the downloaded file MemoryStream ms = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(e.Result ?? "")); // create your reader from the stream of bytes XmlReader reader = XmlReader.Create(ms, settings); // do whatever you want with the reader // ........ // close reader.Close() }