This project has moved. For the latest updates, please go here.

How can I read a <content:encoded> tag?

Topics: Developer Forum, Project Management Forum, User Forum
Aug 31, 2007 at 12:43 AM
Hi guys,
I'm working on some kind of "newspaper" that consumes it's news from various Blog posts. As anyone who has worked with wordpress would know, feeds made by this blogging system divide the main text of every Post (RssItem) in two different tags like this

<description><!CDATA[La corrección política busca adaptarse a las consignas del poder, pero estas muchas veces no coinciden con lo que desean las personas de verdad. La diferencia se ve acá entre los que justifican en televisión los cortes de calles para cualquier estupidez o para sacarle alguna tajada al estado y la opinión de la gente [...]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>La corrección política busca adaptarse a las consignas del poder, pero estas muchas veces no coinciden con lo que desean las personas de verdad. La diferencia se ve acá entre los que justifican en televisión los <a href="http://www.ambitoweb.com/diario/noticia.asp?id=347755&amp;seccion=Informaci%C3%B3n%20General">cortes de calles para cualquier estupidez</a> o para sacarle alguna tajada al estado y la opinión de la gente en las calle que los padece.</p>
<p>Si la no izquierda entendiera la diferencia no se dejaría correr tanto. En Florencia, con un alcalde de izquierda se puso fin a las actividades extorsivas de los “limpia-vidrios”. ¿Se animará la nueva administración de la ciudad a hacer algo así o le temerá a los demagogos de siempre?</p>
</div>]]></content:encoded>

If you speak (or read) spanish you'd realize that the text between de <description></description> tags is just a summary of the text between the <content:encoded></content:encoded> ones, which is the full text for every item.

I've tried reading this <content:encoded> text by using the Description property of a RssItem instance, but I only get the summary text.

Does anyone know if there is any way of reading the whole text using RssToolkit??

Thank you!
Sep 2, 2007 at 12:55 AM
I'm looking for the same answer...anyone?
Oct 9, 2007 at 5:56 PM
The <content:encoded> element is actually from the RDF Site Summary 1.0 Content Module. This is an extension to the syndication specification, so you can expect to see a xmlns:content="http://purl.org/rss/1.0/modules/content/" declaration in the XML data.

I am not completely familiar with the ASP.NET RSS Toolkit, but I would suggest you need to reference this syndication extension and then consume the extension information in whatever way the RSS toolkit provides.
Jan 24, 2008 at 9:55 PM
Here's what I did: In RssItem.cs I added a private field to the RssItem class to hold the encoded content:

private string _encoded;

and then I added a getter/setter that sets and returns this value:

[XmlElement("encoded",
Namespace = "http://purl.org/rss/1.0/modules/content/")]
public string Encoded
{
get
{
return _encoded;
}

set
{
_encoded = value;
}
}

Notice the namespace reference as Oppositional mentions above.


Nov 22, 2008 at 6:06 AM
Edited Nov 22, 2008 at 6:13 AM

There's another gotcha to be aware of if you are creating an RSS feed. In addition to the above, the XmlSerializer needs to know about your "content" domain or it won't write the tags out correctly. Here's my quick and dirty hack to fix this problem. In RssXmlHelper.cs, add this code to the ToRssXml<T>() function.

After this line:

XmlSerializer serializer = new XmlSerializer(typeof(T));

Add the following:
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("content", "http://purl.org/rss/1.0/modules/content/");
ns.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
ns.Add("xsd", "http://www.w3.org/2001/XMLSchema");

Then change the call to .Serialize with this instead:

serializer.Serialize(output, rssDocument, ns);

note the addtion of the namespace parameter. This will make your content:encoded tags render with the missing prefix, which won't work if you don't serialize it with the namespace collection parameter.

-Eric Sassaman

Dec 11, 2008 at 3:31 AM
Also if you want to use the dc namespaces (like dc:creator) add this line too:

ns.Add("dc", "http://purl.org/dc/elements/1.1/");
Feb 16, 2010 at 11:35 AM

Resurrecting an old post here , but I have a need to use a <content:encoded> tag to output some unescaped html content, and I've done the above additions to the source which indeed gives me the correct tag if I set the "Encoded" property of the RSSFeed object. All good so far...

However, the contents of that tag is also escaped, which I don't believe it should be... The top of the feed source looks like this

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="/css/freefx.css" ?>

<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="2.0">
<channel>
<description>Test Feed</description>
<item>
<content:encoded>&lt;![CDATA[&lt;table width="100%" border="0" .......

I would have though the encoded tag should look like this :

      <content:encoded><![CDATA[<table width="100%" border="0"  .......

The XMLSerializer seems to always escape the content of the tags it outputs. Anyone know of a way around this?

Many thanks,

Andrew
Mar 12, 2010 at 4:33 AM

Hi Guys I'm using an RssDataSource and was just wondering in my itemtemplate how would i output the value of the content:encoded tag as i wanted to use the html from the post

<asp:Label ID="descriptionLabel" runat="server" Text='<%# Eval("content:encoded") %>' />

ie that doesn't work!