The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

API returns invalid <atom:content> elements containing unescaped XML data (bug)

Highlighted
Participant

API returns invalid <atom:content> elements containing unescaped XML data (bug)

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.

Paul

3 REPLIES 3
Highlighted
Moderator

Do you have an example of one

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.

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Participant

Missing type for atom:content - see RFC 4287 section 4.1.3.1

According to section 4.1.3.1 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.

Paul

Highlighted
Participant

Workaround/hack in place

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.

Paul

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured