The API returns <atom:content> elements that are apparently invalid, according to the Atom specification, because they contain unescaped XML data. So, I get errors when I try to use the .NET 4.0 System.ServiceModel.Syndication classes to read the Atom feeds and individual entries. This prevents me from using the Atom functionality in .NET as is, requiring ugly workarounds.
Will someone please explain if and when you plan to fix this? Failing that, what have other developers been doing to work around this bug?
So far, I have had to sub-class XmlTextReader and override the ReadElementString method. However, that only fixes reading feeds (lists), not individual items, due to some anomaly I haven't quite figured out yet.
Do you have an example of one of our Atom elements that is invalid and which Atom spec it is invalid against? We can certainly take a look at this, though at this time all of our XML returned shoudl by fully Atom compliant. As such, there is no expected time to fix this. We would need to find an example of it not being valid.
According to section 18.104.22.168 of RFC 4287, which documents the Atom syndication format:
On the atom:content element, the value of the "type" attribute MAY be one of "text", "html", or "xhtml". Failing that, it MUST conform to the syntax of a MIME media type, but MUST NOT be a composite type (see Section 4.2.6 of ). If neither the type attribute nor the src attribute is provided, Atom Processors MUST behave as though the type attribute were present with a value of "text".
Since you are not including a type attribute in your feed, Atom libraries like the System.ServiceModel.Syndication classes in .NET will try to treat your content as plain text, but fail due to the XML elements. You can’t use Atom’s “text”, “html” or “xhtml” types. Instead, you will need to use a MIME type (i.e. <atom:content type=”application/xml”>).
You can validate your feeds with the following site: http://validator.w3.org/feed/. It actually finds at least two errors right now: (1) the XML elements when plain text content is expected and (2) lack of author elements. The second error seems a little erroneous, or at least it doesn’t break the .NET libraries.
I have come up with a workaround for this issue by sub-classing the SyndicationFeed and SyndicationItem classes under System.ServiceModel.Syndication in .NET. I then pass them to the Atom10FeedFormatter and Atom10ItemFormatter classes, respectively, in order to load your feeds and items. My custom SyndicationFeed class overrides the CreateItem method to create a custom SyndicationItem instead. My custom SyndicationItem class then overrides the TryParseContent method to basically treat unspecified content types as XML.
Please note that this is not a general solution for the problem (e.g. Atom feed readers). I can only do this because I know that your content will always be XML.