为数据集调用ReadXml时出现XML解析错误

本文关键字:XML 错误 数据集 调用 ReadXml | 更新日期: 2023-09-27 17:54:23

代码

XmlTextReader reader = new XmlTextReader("http://www.meloy.kommune.no/no/Abonner-pa-nyheter/Nyheter-Meloy-Kommune/");
DataSet ds = new DataSet();
ds.ReadXml(reader);
ds.ReadXml被调用时

导致这个错误:

System.Net。web异常:远程服务器返回一个错误:(500)服务器内部错误。在System.Net.HttpWebRequest.GetResponse ()在System.Xml.XmlDownloadManager。GetNonFileStream(Uri Uri, icredals凭证,IWebProxy代理,RequestCachePolicy cachePolicy)在System.Xml.XmlUrlResolver。gettenentity (Uri绝对Uri,字符串角色,objecttoreturn类型)在System.Xml.XmlTextReaderImpl。xmlResolver OpenUrlDelegate(对象)在System.Threading.CompressedStack.runTryCode(对象userData)在System.Runtime.CompilerServices.RuntimeHelpers。ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode, backoutCode, Object userData)在System.Threading.CompressedStack。运行(CompressedStack CompressedStack, ContextCallback, callback, Object state)在System.Xml.XmlTextReaderImpl.OpenUrl ()在System.Xml.XmlTextReaderImpl.Read ()在System.Xml.XmlReader.MoveToContent ()在System.Data.DataSet。ReadXml(XmlReader阅读器,布尔值denyresolved)在ASP.templates_units_rsslistingtest_ascx。LoadFeedServer(字符串url)在ASP.templates_units_rsslistingtest_ascx。SetupDataGridServer (Int32 max)

错误的原因是什么?如何解决?

编辑:如此:

WebClient wc = new WebClient();
Stream st = wc.OpenRead("d:''episerver''test.xml");
        string rss ="";
        using (StreamReader sr = new StreamReader(st)) {
           rss = sr.ReadToEnd();
        }
         XmlReader reader = XmlReader.Create(new StringReader(rss));
        DataSet ds = new DataSet();
        ds.ReadXml(reader);         

为数据集调用ReadXml时出现XML解析错误

我认为这与c# web请求创建的头有关。这个线程似乎处理相同的问题:

如何在不提供凭据的情况下将安全rss提要读取到SyndicationFeed中?