2014-10-26 2 views
3

Я пытаюсь сделать приложение RSS для Windows Phone 8, но возникает ошибка, когда я пытаюсь загрузить содержимое RSS с помощью XmlReader.W8 Phone System.Xml.XmlException с 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(); 

Ошибка находится на линии «читатель XmlReader = XmlReader.Create ....» Сообщение полная ошибка:

Первый шанс исключение типа «System.Xml.XmlException» произошло in System.Xml.ni.dll

Дополнительная информация: Не удается открыть 'http://feeds.bbci.co.uk/news/business/rss.xml'. Параметр Uri должен быть относительным путем файловой системы.

Благодарим за помощь! :)

ответ

2

Вы получаете эту ошибку, потому что она ожидает, что файл в LocalStorage не является веб-адресом. Таким образом, вы должны загрузить файл и преобразовать его в течение примерно так:

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.DownloadStringCompleted += new DownloadStringCompletedEventHandler(FileDownloadComplete); 

    // start the download 
    downloader.DownloadStringAsync(uri); 
} 

// this event will fire if the download was successful 
void FileDownloadComplete(object sender, DownloadStringCompletedEventArgs 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() 
} 
+0

Здравствуйте, спасибо за ваш ответ, хотя он испускает другую ошибку: первый шанс исключение «System.ArgumentException» типа произошло в mscorlib.ni .dll Дополнительная информация: Использование неопределенного значения ключевого слова 1 для события TaskScheduled. @ChubosaurusSoftware – user3795349

+0

@ user3795349 В коде нет ошибок, создайте новый проект и вставьте его. Ошибки, которые вы испытываете, - это результат чего-то еще, что вы делаете. –

Смежные вопросы