XmlDocument.LoadXml()抛出一个异常的类型收到COMException的 [英] XmlDocument.LoadXml() throws an exception of type ComException
问题描述
我试图解析从<一个返回的XML文档href="http://www.onlinetvrecorder.com/?aktion=epg_export&format=xml&btn_ok=OK&stations=3SAT,ANIXE,ARD&from=30.11.2011&to=30.11.2011"相对=nofollow>此链接,但我得到一个异常类型的收到COMException
以下消息:
错误HRESULT E_FAIL已返回通过调用COM组件。
这里的code:
尝试
{
// ...
字符串EPGXML =等待DownloadAsync(URL);
VAR xmlDoc中=新的XmlDocument();
xmldoc.LoadXml(EPGXML); //此行引发异常
//...rest的code
}
赶上(例外)
{
//我来到这里...
}
能否请你帮我,为什么我得到这个消息,我该如何解决这一问题?谢谢你。
编辑:
我在读使用此功能(也许我错了,在这里,我应该做些什么来获取字符串中的UTF-8,因为我没有看到德国的字符字符串在调试中的XML源模式(监视窗口):
专用异步静态任务&LT;字符串&GT; DownloadPageAsync(字符串URL)
{
尝试
{
HttpClientHandler处理器=新HttpClientHandler();
handler.UseDefaultCredentials = TRUE;
handler.AllowAutoRedirect = TRUE;
handler.UseCookies = TRUE;
HttpClient的客户端=新的HttpClient(处理);
client.MaxResponseContentBufferSize =千万;
HTT presponseMessage响应=等待client.GetAsync(URL);
response.EnsureSuccessStatus code();
字符串responseBody = response.Content.ReadAsString();
返回responseBody;
}
赶上(例外前)
{
回归错误+ ex.Message;
}
}
您提供的XML是无效的,至少这就是火狐说:
ERREUR D'分析XML:MAL FORME 炮台:<一href="http://www.onlinetvrecorder.com/?aktion=epg_export&format=xml&btn_ok=OK&">http://www.onlinetvrecorder.com/?aktion=epg_export&format=xml&btn_ok=OK&>stations=3SAT,ANIXE,ARD&from=30.11.2011&to=30.11.2011 NUMERO德LIGNE 218,Colonne的193:
(对不起,法文)
看起来有点接近,它看起来像单词Plötzlich分析器休息,在字符0。
您应该使用CDATA至prevent这样的:
&LT;![CDATA [您的文字这里可以包含特殊字符]]&GT;
I'm trying to parse the xml document returned from this link but I get an exception of type ComException
with the following message:
Error HRESULT E_FAIL has been returned from a call to a COM component.
Here's the code:
try
{
//...
string EPGXML = await DownloadAsync(url);
var xmldoc = new XmlDocument();
xmldoc.LoadXml(EPGXML); //this line throws the exception
//...rest of the code
}
catch (Exception)
{
//I get here...
}
Could you please help me why I get this message and how can I fix this? Thanks.
EDIT:
I'm reading the source of the XML using this function (maybe I'm wrong here and I should do something to get the string in UTF-8, because I don't see the German characters in the string in debug mode (watch window):
private async static Task<string> DownloadPageAsync(string url)
{
try
{
HttpClientHandler handler = new HttpClientHandler();
handler.UseDefaultCredentials = true;
handler.AllowAutoRedirect = true;
handler.UseCookies = true;
HttpClient client = new HttpClient(handler);
client.MaxResponseContentBufferSize = 10000000;
HttpResponseMessage response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
string responseBody = response.Content.ReadAsString();
return responseBody;
}
catch (Exception ex)
{
return "error" + ex.Message;
}
}
The XML you provided is not valid, at least that's what Firefox says:
Erreur d'analyse XML : mal formé Emplacement : http://www.onlinetvrecorder.com/?aktion=epg_export&format=xml&btn_ok=OK&>stations=3SAT,ANIXE,ARD&from=30.11.2011&to=30.11.2011 Numéro de ligne 218, Colonne 193 :
(Sorry for the french)
Looking a bit closer, it looks like the parser breaks on the word "Plötzlich", on the character "ö".
You should use CDATA to prevent this:
<![CDATA[Your text here can contain special chars]]>
这篇关于XmlDocument.LoadXml()抛出一个异常的类型收到COMException的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!