1

我尝试从 Yandex-Fotki (Image Hoster) 解析一个 HttpWebRequest。我收到 Atom 格式的响应,但在 SyndicationFeed 中出现错误:名称为“服务”和命名空间“ http://www.w3.org/2007/app ”的元素不是允许的提要格式。

我的代码是:

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>

我希望你能帮帮我!

4

1 回答 1

1

SyndicationFeed只会使用AtomRSS Syndication 格式解析 XML。Yandex-Fotki 网站的反应似乎也不是。

好的,我发现了一个东西,也许它就是你要找的东西。如果你在你的网络浏览器中请求一个<collection href="http://api...">值,你会得到一个 Atom Syndication 格式的 XML。

在此处输入图像描述

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

使用 XMLReader 读取 DOM 或将其反序列化为自定义类或将 XML 加载到数据集或 LINQ to XML。

于 2015-02-23T13:38:16.813 回答