R
R
redisco2013-01-18 09:52:53
RSS
redisco, 2013-01-18 09:52:53

Correct layout of RSS?

Good day. On the topic of the subject: I'm interested in how your RSS is typeset, and specifically what to do with tags? Delete or put in <![CDATA[]]>? I found a guide to creating RSS for news.yandex.ru, but nothing was said about tags there.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander Rabotyahoff, 2013-01-19
@Holden

Generally rss must be valid xml.
The XML tells us that whatever data is inside <![CDATA[]]> will be output to the result tree as is. Those. if there is a < character in the node value, then it is better to use <![CDATA[]]>. Also note that xml does not understand   mnemonics. Instead, you need to write &nbsp; or use <![CDATA[]]>.
For example, in the c_xml class ( www.phpclasses.org/package/7232-PHP-Convert-between-XML-files-and-arrays-or-strings.html ) I do this

static function valueToXML($value){
    if (mb_strpos($value,'<')!==false || mb_strpos($value,'&')!==false) {
      $value="<![CDATA[$value]]>";
    }
    return $value;
  }

This code has a drawback - it does not take into account non-printable characters.
But there will be no error if you use <![CDATA[]]> everywhere indiscriminately. Validators will validate and RSS readers will read.
Also remember that the string "<![CDATA[]]>" itself may be present in the node value. In this case, I recommend replacing it with the line <![CDATA[]]>

M
Max, 2013-01-18
@AloneCoder

I don't think adding or removing <![CDATA[]]> will take long, check with the validator

S
startsevdenis, 2013-01-18
@startsevdenis

Everything is simple with Yandex, if you have tags in rss, then you must use <![CDATA[]]>, if not, don’t use it, well, you need to replace special characters, that is, Yandex does not impose any restrictions. Therefore, it's easier to use <![CDATA[]]>.

G
GRADUSnick, 2013-01-19
@GRADUSnick

I use the php class from habrovchanin zelenin. The class itself is here github.com/zelenin/rssgen Validation of RSS passes, without any CDATA.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question