1

请帮助我解除 xml 文档的实现。我试着这样做

 public class SearchItem
    {
        [XmlAttribute("url")]
        public string Url { get; set; }
        [System.Xml.Serialization.XmlAttribute("title")]
        public string Title { get; set; }
        [System.Xml.Serialization.XmlAttribute("headline")]
        public string Content { get; set; }
        public SearchItem()
        {
        }
        public SearchItem(string url, string title, string content)
        {
            Url = url;
            Title = title;
            Content = content;
        }
    }

然后我尝试反序列化,但我有异常 inputData - 是我从 WebClient 获得的 Strem 女巫,其中是来自服务器的答案

 XmlObjectSerializer xos = new DataContractSerializer(typeof(SearchItem));
            var ss = (List<SearchItem>)xos.ReadObject(inputData);

来自服务器示例的答案:

<yandexsearch version="1.0">
<request>
<query>
арбитр
</query>
<page>
0
</page>
<sortby order="descending" priority="no">
rlv
</sortby>
<maxpassages/>
<groupings>
<groupby attr="d" mode="deep" groups-on-page="10" docs-in-group="1" curcateg="-1"/>
</groupings>
</request>
<response date="20120612T200646">
<reqid>
1339531606485424-918142884478824595311381-3-022-XML
</reqid>
<wordstat>
ban: 0,арбитр: 4895441
</wordstat>
<found priority="phrase">
5178271
</found>
<found priority="strict">
5178271
</found>
<found priority="all">
5178271
</found>
<found-human>
Нашлось 5 млн ответов
</found-human>
<results>
<grouping attr="d" mode="deep" groups-on-page="10" docs-in-group="1" curcateg="-1">
<found priority="phrase">
17461
</found>
<found priority="strict">
17461
</found>
<found priority="all">
17461
</found>
<found-docs priority="phrase">
5171740
</found-docs>
<found-docs priority="strict">
5171740
</found-docs>
<found-docs priority="all">
5171740
</found-docs>
<found-docs-human>
нашёл 5 млн ответов
</found-docs-human>
<page first="1" last="10">
0
</page>
<group>
<categ attr="d" name="arbitr.ru"/>
<doccount>
47282
</doccount>
<relevance priority="all"/>
<doc id="78-19-6-Z719CDE9C6DE1107F">
<relevance priority="phrase"/>
<url>
http://www.arbitr.ru/
</url>
<domain>
www.arbitr.ru
</domain>
<title>
"Высший арбитражный суд Российской Федерации" 
</title>
<headline>
Новости, обзоры деятельности арбитражных судов, пресс-релизы. Арбитражная сиcтема РФ: правовые основы, контакты региональных арбитражных судов и др. Постановления ВАС РФ, нормативные документы.
</headline>
<modtime>
20061008T212457
</modtime>
<size>
50143
</size>
<charset>
windows-1251
</charset>
<properties>
<_PassagesType>
0
</_PassagesType>
<lang>
ru
</lang>
</properties>
<mime-type>
text/html
</mime-type>
<saved-copy-url>
http://hghltd.yandex.net/yandbtm?text=%D0%B0%D1%80%D0%B1%D0%B8%D1%82%D1%80&url=http%3A%2F%2Fwww.arbitr.ru%2F&fmode=inject&mime=html&l10n=ru&sign=168f7a8cc92b73dd647be5ca4a0d91b8&keyno=0
</saved-copy-url>
</doc>
</group>
</grouping>
</results>
</response>
</yandexsearch>

谢谢你的帮助/

i have a solution of my problem, but it is not Deserialization, its simple xml working, like this:

  XDocument xmlResponse = XDocument.Parse(page);
        var groupQuery = from elements in xmlResponse.Elements().
            Elements("response").
            Elements("results").
            Elements("grouping").
            Elements("group")
                         select elements;

var items = new List<SearchItem>(listSize);
            foreach (var item in groupQuery)
            {
                string urlQuery = GetValue(item, name: "url");
                string titleQuery = GetValue(item, name: "title");
                string descriptionQuery = GetValue(item, name: "headline");
                SearchItem additionItem = new SearchItem(urlQuery, titleQuery, descriptionQuery);
                items.Add(additionItem);
            }

但我需要反序列化的解决方案....

4

0 回答 0