解析Atom响应时出错

我尝试从Yandex-Fotki解析HttpWebRequest(Image Hoster)。我以Atom格式获得响应,但在SyndicationFeed中出现错误:名称为'service'且名称空间为'http://www.w3.org/2007/app'的元素不是允许的Feed格式。解析Atom响应时出错

我的代码是:

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>

我希望你能帮帮我!

回答:

SyndicationFeed将只解析XML Atom或RSS整合格式。网站Yandex-Fotki的回应似乎并不是这样。

好吧,我发现一件事情,也许这是你在找什么。如果您在网页浏览器中请求<collection href="http://api...">值,则会以Atom Syndication格式获得XML。

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

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

以上是 解析Atom响应时出错 的全部内容, 来源链接: utcz.com/qa/265187.html

回到顶部