Welcome to PhoneASK, where you can ask questions and receive answers from other members of the community.

W8 Phone System.Xml.XmlException with XmlReader

asked 一月 11 at 23:22 by Duncan Edwards Jones

I am trying to make a RSS app for Windows Phone 8 but there is an error occurring whenever I try to download the RSS content using a 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();

The error is found on the line "XmlReader reader = XmlReader.Create...." The full error message is:

A first chance exception of type 'System.Xml.XmlException' occurred in System.Xml.ni.dll

Additional information: Cannot open 'http://feeds.bbci.co.uk/news/business/rss.xml'. The Uri parameter must be a file system relative path.

Thank you for your help! :)

Your answer

1 Answers

answered 一月 12 at 04:41 by Scott Cameron

You're getting that error because it's expecting a file in LocalStorage not a web address. So you have to download the file and convert it over like so:

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()
}

Related Questions

I am trying to get a XML content from here link. Then get the content of item element to display on screen. It's kind of RSS Reader on WP7. The issue were when I examine the content, the bytes seems
I'm kinda new to WP8 development and I have to reuse huge legacy codebase (C++, ATL, WIN32). Is there ATL support for Windows Phone 8? Or what?
Is there really a 4 icon item limit on the applicationbar in windows phone 8? I tried to create a 5th element and it gave me an error in visual studio 2012 for windows phone that too many items were i
How do you convert XmlReader to XmlTextReader? Code Snippet: XmlTextReader reader = XmlTextReader.Create(pomfile.FullName); Here's the Build error I got: Cannot implicitly convert type 'System.Xml.Xm
I develop an app for Windows Phone 8 and use Task Agent. I need to debug code that used in Task Agent. I try to join the process in menu Debug - Join the process, but when I choose the right qualifier
I am currently developing an image processing/editing kind of app in which I am applying various effects to an image taken by camera/Gallery. Recently I read about NFC for windows phone 8, and I would
I'm writing a sample windows phone 8 application. I've also installed the framework Async for .NET Framework 4, Silverlight 4 and 5, and Windows Phone. But, await on a method doesn't wait and my mainp
I need to display PDF files in my windows phone 8 app. The easiest way I know is using ComponentOne pdf control. But it is way too costly to be bought by an individual. Is any body aware of a free wp8
Is there a unified way of developing app that works on both Windows 8 and Windows Phone 8. What I mean is that, can I make a single solution/project base or do I need to create different solutions, a
I recently was able to successfully set an Image's source as a GIF image, using: image.Source = new BitmapImage(new Uri(http://imageurl/image.gif) I currently have to use a substantial amount of ex
I'm trying to render some html content with a WebBrowser xaml control. The html content varies in length. The control is placed within a grid with single row at the moment. I would like to place other
May I know, can A Windows 8 Store App source project (Metro), link with binary reference initially created for Windows Phone 7? A Windows 8 Store App source project (Metro), link with binary referenc
We are planning to use the Cycle Template for the Application Tile. Moreover, we would like to display specific images when the user has pinned a Wide Application Tile and other images when the user h
I have searched the official forums and documentation and all other places, but haven't been able to find a concrete answer. Q. In Windows Phone 8, is it possible for an application to respond to a Pu
I'm currently developing an app which has single sign on via Windows Azure Access Control Service. I am using the Access Control Service for Windows Phone NUGET package (the same control can also be f
Update: Going further with my investigation, I just submitted a test app in beta store to just show the values of CurrentApp.LicenseInformation.IsActive and CurrentApp.LicenseInformation.IsTrial. Both
I need to navigate from one xaml page to another with an Object not a String .. present code is : private void Border_ManipulationStarted(object sender, System.Windows.Input.ManipulationStartedEvent
I'm trying to port an app from Windows 8 to Windows Phone 7 and having a hard time trying to figure out equivalents of these lines var localFolder = ApplicationData.Current.LocalFolder; IReadOnlyList
This may sound really NOOBI! I have a LongListSelector for showing some items in my app, and I wanted to add this cool effect called TiltEffect to the items so they show some interaction as user taps
How can I use Microsoft Templates to create Calendar Control ? Can someone provide me a code for this ? or which references should I have to create a calendar. And one more question, how references ar
How do you think? Could I use my Sony Vaio for development?
Possible Duplicate: Referencing ZXing.Net library I'm developing an application that targetting Windows phone 8.0 OS When I try to add a reference of version (7.1) to the application , it gives the
I'm porting an app from Windows Phone 7 to Windows Phone 8 and am having some problems with the PathListBox control. Here's the XAML: <Grid x:Name=LayoutRoot Background={StaticResource PhoneChro
What drawing methods can I use in the Win 8 Phone SDK to manually draw single pixels on the screen, like in a drawing app? It doesn't matter if its c#, c++ or something else.
Is there a way to programmatically copy/paste text in windows phone 8. I want to copy the contents from the clipboard when user clicks a button. Any thoughts?
I'm wondering if it is possible to use my windows phone 8 as a virtual keyboard and mouse (HID) for any device that has bluetooth support with out creating software to install on the receiving compute
Hi, I want my windows phone 8 application to sync automatically, when a row is inserted in a table. That is, a xaml page in my app displays all the data in a table. 1. So, if a new row is added t
I've been trying to find an easy way to write XML using the XmlReader/XmlWriter. I don't really like using the interface IXmlSerializable, but I've got no choice for some of my dataclass. Anyway, wh
Please help me to make Longlistselector with Horizontal scroll in Windows phone 8. And I make the longlistselector follow this link: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj2443
In my image editing application i am providing two option to the user, 1) save image to Media library and another share it through ShareMediaTask. The issue i am facing is while saving the image to li
I know this seems basic, but I have spent hours looking at docs and videos and cant seem to find the answer. Sorry if I'm being a doof. Is there a difference between Windows 8 App Store Development an
I have an object which i am using almost all windows phone pages, currently i am using via PhoneApplicationService.Current.State[xx] = m_xx; NavigationService.Navigate(new Uri(/abc.xaml, UriKind.
I would like to create an App for WP8 using the Nokia Imaging SDK where I can take some photos using the phone camera and then apply a kind of predefined templates over the photo that was just taken.
I use the DeviceUniqueId property of the DeviceExtendedProperties object to identify a device on my Windows Phone apps. On Windows Phone 7, it worked perfectly, and the device id remained stable acros
I am creating a project for windows phone, and have made numerous backups over the past month, however when I ran the project this morning I received a Value does not fall within the excepted range er
Is there any unique device ID (UDID) or any similar ID I can read out on Windows Phone 8 (WP8) that doesn't change with hardware changes, app-reinstallation etc.? In older Windows Phone versions there
I am working on a Windows Phone 8 and Windows Store app that involves in Amazon Web Services (AWS). Is there an official AWS SDK available for these platforms? I found AWS SDKs for iPhone and Android
How to disable tap on few pages in Windows phone 8? The pages of the applications are designed and developed using HTML5.
Any project that I try on my computer will give this error in VS2012 when I try to compile after adding the attribute for fast app resume in WMAppManifest.xml: The 'ActivationPolicy attribute is not
I am developing a Windows Phone 8 application. How can I exit or quit programmatically (through code) from my Windows Phone 8 app? What are the various ways in which I can programmatically (through c
Currently developing a Windows Phone 8 application in pure C++/Direct3D. We now need to access the Device Manufacturer name but it seems to only be available under C# which, according to my research i
I've managed to setup code for a Windows Phone 8 Application that initializes and can start/stop recording video using an AudioVideoCaptureDevice. (saves it to an IRandomAccessStream) //Initialize Cam
I have a two WP8 projects. This is projects with map. First project with new Nokia maps and second project with old Bing maps. I noticed inappropriate behavior of old maps. They consume large amounts
I'm trying to disable the scrolling and zooming on the WebBrowser control on Windows Phone 8 without using any HTML tags. I've found a few articles about this but they're all for Windows Phone 7 and I
I am attempting to establish an app-to-app bluetooth connection programmatically. Please see the following code snippet for the said purpose: StreamSocket streamSocket = await PeerFinder.ConnectAsync(
I've recently bought a HTC Windows Phone 8X. Pretty nice device so far. But the sensor-keys on the bottom of the device are very sensitive and touching them accidentally (what happens quite often) is
According to Brett Jankord's Cross Browser Retina/High Resolution Media Queries Windows 8 phones do not support any of the device-pixel-ratio media queries. Is there another way to target windows ph
I need to create a list view in Windows Phone 8 to display the following debug information (what follows is my code that currently displays messages in Debug.WriteLine). contacts.SearchCompleted += (
I am working on an Windows Phone 8 Application that uses mixed C# for UI and C++ for the underlying backed. I have some instances where I need to run some C++ code on the UI dispatcher thread (IE GetG
Hey everyone I'm in the process of writing a Windows phone 8 that is a copy of a clients iOS application. I need to be able to send a get request with custom header entries. Using Windows 8 this is ea
...