解析Atom响应时出错

时间:2015-02-23 12:11:26

标签: c# xml parsing atom-feed yandex

我尝试从Yandex-Fotki(Image Hoster)解析HttpWebRequest。我在Atom-Format中得到了回复,但是在SyndicationFeed中我收到一个错误:名称为' service'和命名空间' http://www.w3.org/2007/app'不是允许的Feed格式。

我的代码是:

XmlReader reader = XmlReader.Create(new StringReader(response));
            SyndicationFeed feed = SyndicationFeed.Load(reader);

以下是输入(来自网站的回复):

<app:service xmlns:app="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom">
  <app:workspace>
    <atom:title>packda на Яндекс.Фотках</atom:title>
    <app:collection href="http://api-fotki.yandex.ru/api/users/packda/albums/" id="album-list">
      <atom:title>Все альбомы пользователя packda</atom:title>
      <app:accept>application/atom+xml; type=entry, application/json; type=entry</app:accept>
    </app:collection>
    <app:collection href="http://api-fotki.yandex.ru/api/users/packda/photos/" id="photo-list">
      <atom:title>Все фотографии пользователя packda</atom:title>
      <app:accept>image/*</app:accept>
      <app:categories scheme="http://api-fotki.yandex.ru/api/users/packda/tags/" />
    </app:collection>
    <app:collection href="http://api-fotki.yandex.ru/api/users/packda/tags/" id="tag-list">
      <atom:title>Все теги пользователя packda</atom:title>
      <app:accept />
    </app:collection>
  </app:workspace>
</app:service>

我希望你能帮助我!

1 个答案:

答案 0 :(得分:1)

SyndicationFeed只会使用AtomRSS联合格式解析XML。 Yandex-Fotki网站的反应似乎都没有。

好的,我找到了一件可能就是你要找的东西。如果您在Web浏览器中对<collection href="http://api...">值进行请求,则会获得Atom Syndication格式的XML。

enter image description here

这是您必须使用SyndicationFeed解析的XML。因此,您必须检索集合元素的href值,获取该XML并将其加载到SyndicationFeed中。要退出集合元素,您可以尝试:

使用XMLReader读取DOM或将其Deserilize为自定义类或将XML加载到DataSet或LINQ to XML。