Ali*_*ori 2 .net c# xml windows-runtime
我正在尝试解析从此链接返回的xml文档,但我得到类型的异常,ComException并带有以下消息:
Error HRESULT E_FAIL has been returned from a call to a COM component.
这是代码:
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...
}
Run Code Online (Sandbox Code Playgroud)
能帮到我,为什么我收到这条消息,我该如何解决这个问题?谢谢.
编辑:
我正在使用这个函数读取XML的源代码(也许我在这里错了,我应该做一些事情来获取UTF-8中的字符串,因为我没有在调试模式下看到字符串中的德语字符(watch窗口):
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;
}
}
Run Code Online (Sandbox Code Playgroud)
您提供的XML无效,至少Firefox的说法如下:
Erreur d'analyze XML:malforméImplacement:http://www.onlinetvrecorder.com/?dog = epg_export&format = xml&btn_ok = OK&> stations = 3SAT,ANIXE,ARD&from = 30.11.2011&to =30.11.2011Numérodeligne 218,Colonne 193:
(对不起法国人)
看得更近一点,看起来解析器打破了字符"ö"上的"Plötzlich"这个词.
您应该使用CDATA来防止这种情况:
<![CDATA[Your text here can contain special chars]]>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4967 次 |
| 最近记录: |