为什么XDocument.Parse抛出NotSupportedException?我正在尝试使用XDocument.Parse解析xml数据wchichthrowsNotSupportedException,如主题:IsXDocument.ParsedifferentinWindowsPhone7?我根据发布的建议更新了我的代码,但它仍然无济于事。前段时间我使用了一种类似(但更简单)的方法来解析RSS,并且效果很好。publicvoidsList(){WebClientclient=newWebClient();client.Encoding=Encoding.UTF8;字符串url="http://eztv.it";Uriu=newUri(url);client.DownloadStringAsync(u);client.DownloadStringCompleted+=newDownloadStringCompletedEventHandler(client_DownloadStringCompleted);}privatevoidclient_DownloadStringCompleted(objectsender,DownloadStringCompletedEventArgse){try{strings=e.Result;s=切割(s);XmlReaderSettingssettings=newXmlReaderSettings();settings.DtdProcessing=DtdProcessing.Ignore;XDocumentdocument=null;//XDocument.Parse(s);//Load(s);使用(XmlReaderreader=XmlReader.Create(newStringReader(e.Result),settings)){document=XDocument.Load(reader);//此处抛出错误}//...其余代码}catch(Exceptionex){MessageBox.Show(ex.Message);}}stringcut(strings){intiod=s.IndexOf("");intido=s.LastIndexOf("");s=s.Substring(iod,ido-iod+9);返回s;}当我用字符串替换//strings="10ThingsIHateAboutYou2BrokeGirls";一切正常,没有抛出异常,那么我做错了什么?在e.Result中有像'&'这样的特殊符号我只是尝试用HttpUtility.HtmlEncode()符号替换它(除''、'"'HttpUtility.HtmlEncode()和XDocument之外的所有符号UPD:我不想显示我的代码,但你没有给我机会:)stringy="";for(inti=0;i'||s[i]=='"'){y+=s[i];}else{y+=HttpUtility.HtmlEncode(s[i].ToString());XDocumentdocument=XDocument.Parse(y);varoptions=(fromoptionindocument.Descendants("option")selectoption.Value).ToList();它适用于我的WP7。请不要使用这个html转换的代码,为了测试我赶紧写了上面是C#学习教程:WhydoesXDocument.ParsethrowNotSupportedException?分享的全部内容,如果对大家有用需要进一步了解C#学习教程,希望大家多多关注—本文采集自网络,不代表立场,如涉及侵权,请点击右边联系管理员删除,转载请注明来源:
