返回的xml包含转义字符 "

本文关键字:quot 转义字符 包含 xml 返回 | 更新日期: 2023-09-27 18:08:06

我使用RestSharp查询MyAnimeList.net,但返回的xml包含转义'n和'"

我使用这个代码

private string MyAnimeListSearch(string searchFor)
{
    var client = new RestClient();
    client.BaseUrl = new Uri("http://myanimelist.net");
    client.Authenticator = new HttpBasicAuthenticator("*****", "*****");
    var request = new RestRequest(Method.GET);
    request.Resource = "/api/anime/search.xml";
    request.AddParameter("q", searchFor);
    // execute the request
    IRestResponse response = client.Execute(request);
    string content = response.Content;
    return content;
}

我正在获取这个内容

"<?xml version='"1.0'" encoding='"utf-8'"?>'n<anime>'n <entry>'n 
<id>727</id>'n <title>Kingyo Chuuihou!</title>'n <english>Goldfish 
Forecast!</english>'n <synonyms>Goldfish Warning!</synonyms>'n 
<episodes>54</episodes>'n <score>6.86</score>'n <type>TV</type>'n 
<status>Finished Airing</status>'n <start_date>1991-01-12</start_date>'n 
<end_date>1992-02-29</end_date>'n <synopsis>The show starts with the 
tale of Chitose Fujinomiya, a girl who goes from riches to rags and back 
and remains a snob despite it all. When her wealthy father dies, 
remaining debts leave Chitose almost broke, and she is kicked out of the 
affluent Tokai no Gakuen, or City Academy. She is left with nothing in 
the world but the clothes on her back and one pink goldfish named 
Gyopi-chan, the only memento she has of her father. Wandering lost, she 
collapses on the grounds of the poor-but-happy Inaka no Chugakko 
(Country Jr. High School), where the students are rough if friendly, and 
farm animals regularly roam the school grounds and even attend class. 
Recovering, she enters into the school but is repelled by its air of 
poverty, to which she is unaccustomed. &lt;br /&gt;'n&lt;br 
/&gt;'n(Source: AnimeNfo)</synopsis>'n 
<image>http://cdn.myanimelist.net/images/anime/13/26657.jpg</image>'n 
</entry>'n <entry>'n <id>3155</id>'n <title>Kingyo Chuuihou! 
(Movie)</title>'n <english></english>'n <synonyms>Goldfish Warning! The 
Movie</synonyms>'n <episodes>1</episodes>'n <score>6.38</score>'n 
<type>Movie</type>'n <status>Finished Airing</status>'n 
<start_date>1992-04-25</start_date>'n <end_date>1992-04-25</end_date>'n 
<synopsis>A super-short fast paced theatrical animation about Wapiko and 
friends. </synopsis>'n 
<image>http://cdn.myanimelist.net/images/anime/8/16452.jpg</image>'n 
</entry>'n</anime>'n" 

为什么?是RestSharp还是MyAnimeList.net导致"错误"

如何修复?

返回的xml包含转义字符
 "

    Dictionary<string, string> replacements = new Dictionary<string, string>();
    replacements.Add("''n", Environment.NewLine);
    replacements.Add("''t", "   ");
    replacements.Add("''r", Environment.NewLine);
    replacements.Add("''f", "");
    replacements.Add("''v", "");
    replacements.Add("'''"", "'"");
    foreach (KeyValuePair<string, string> escapeSequence in replacements)
    {
        content = content.Replace(escapeSequence.Key, escapeSequence.Value);
    }
    XDocument doc = XDocument.Parse(content);
    content = doc.ToString();