Search code examples
c#xmlparsingatom-feedyandex

Error during parsing of Atom response


I try to parse a HttpWebRequest from Yandex-Fotki (Image Hoster). I get a response in Atom-Format, but in SyndicationFeed I get an error: The element with name 'service' and namespace 'http://www.w3.org/2007/app' is not an allowed feed format.

My Code is:

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

Here is the input(response from the site):

<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>

I hope you can help me!


Solution

  • SyndicationFeed will only parse XML with Atom or RSS Syndication Format. The response of the site Yandex-Fotki doesn't seem to be neither.

    Ok, I found a thing that maybe it is what you are looking for. If you do a request in your webbrowser of a <collection href="http://api..."> value you get a XML in Atom Syndication format.

    enter image description here

    This is the XML you have to parse with SyndicationFeed. So, you have to retrieve the href value of collection elements, get that XML and load it in SyndicationFeed. To retireve the collection elements you can try:

    Read DOM with XMLReader OR Deserilize it to a custom class OR Load XML into a DataSet OR LINQ to XML.