1

使用此代码,它表明没有错误,但是运行时它不断崩溃,下面是代码,然后是调试输出;

using System.Xml;
using System.Net;
using System.ServiceModel.Syndication;

XmlReaderSettings settings = new XmlReaderSettings();
        settings.DtdProcessing = DtdProcessing.Ignore;

        XmlReader reader = XmlReader.Create("https://news.google.com/news/feeds?pz=1&cf=all&ned=uk&hl=en&q=" + "google" + "&output=rss", settings);
        SyndicationFeed feed = SyndicationFeed.Load(reader);
        reader.Close();

这是调试输出:

A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.ArgumentException' occurred in System.Windows.ni.dll
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\en-US\System.Xml.debug.resources.DLL'. Module was built without symbols.
A first chance exception of type 'System.Xml.XmlException' occurred in System.Xml.ni.dll
'TaskHost.exe' (CoreCLR: Silverlight AppDomain): Loaded 'C:\windows\system32\en-US\mscorlib.debug.resources.dll'. Module was built without symbols.
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in Microsoft.Phone.ni.dll

调用堆栈信息:

project.DLL!project.App.RootFrame_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e) 第 90 行 C# Microsoft.Phone.ni.dll!System.Windows.Navigation.NavigationService.RaiseNavigationFailed(System.Uri uri, System.异常异常) 未知 Microsoft.Phone.ni.dll!System.Windows.Navigation.NavigationService.ContentLoader_BeginLoad_Callback(System.IAsyncResult 结果) 未知 Microsoft.Phone.ni.dll!System.Windows.Navigation.PageResourceContentLoader.BeginLoad_OnUIThread(System.AsyncCallback userCallback , System.Windows.Navigation.PageResourceContentLoader.PageResourceContentLoaderAsyncResult 结果) 未知 Microsoft.Phone.ni.dll!System.Windows.Navigation.PageResourceContentLoader.BeginLoad.AnonymousMethod__0(object args) 未知 [本机到托管转换]
mscorlib.ni.dll!System.Delegate.DynamicInvokeImpl(object[] args) 未知 System.Windows.ni.dll!System.Windows.Threading.DispatcherOperation.Invoke() 未知 System.Windows.ni.dll!System.Windows。 Threading.Dispatcher.Dispatch(System.Windows.Threading.DispatcherPriority 优先级) 未知 System.Windows.ni.dll!System.Windows.Threading.Dispatcher.OnInvoke(对象上下文) 未知 System.Windows.ni.dll!System.Windows。 Hosting.CallbackCookie.Invoke(object[] args) 未知 System.Windows.RuntimeHost.ni.dll!System.Windows.RuntimeHost.ManagedHost.InvokeDelegate(System.IntPtr pHandle, int nParamCount, System.Windows.Hosting.NativeMethods.ScriptParam* pParams, System.Windows.Hosting.NativeMethods.ScriptParam* pResult) 未知

感谢您的帮助

4

1 回答 1

1

public void FileDownloadComplete(object sender, DownloadStringCompletedEventArgs e) { // e.Result 将逐字节包含文件

// 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()
于 2014-10-27T11:41:46.173 回答