Avoid Using "< [Cdata[ ]]>" in RSS(waspdev.com) |
Avoid Using "< [Cdata[ ]]>" in RSS(waspdev.com) |
Do use CDATA nodes, but only work on XML with an actual XML DOM library instead of string manipulation. Browsers have these built-in (DOMParser).
> The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings " & " and " < " respectively. The right angle bracket (>) may be represented using the string " > ", and MUST, for compatibility, be escaped using either " > " or a character reference when it appears in the string " ]]> " in content, when that string is not marking the end of a CDATA section.
> In the content of elements, character data is any string of characters which does not contain the start-delimiter of any markup and does not include the CDATA-section-close delimiter, " ]]> ". In a CDATA section, character data is any string of characters not including the CDATA-section-close delimiter, " ]]> ".
> To allow attribute values to contain both single and double quotes, the apostrophe or single-quote character (') may be represented as " ' ", and the double-quote character (") as " " ".
The description contains HTML markup, such as <p></p> for paragraph breaks. CDATA is a nice and clean way to encode them without breaking anything.
The title doesn't contain any markup, and shouldn't. A good old escape function covers both the "doesn't" part and the "shouldn't" part.
I see people stuffing all sorts of HTML tags and nonstandard attributes in an RSS <description>, just because CDATA allows them to do so without breaking the parser. Images, videos, inline SVGs with maybe some scripts inside...
The RSS spec should never have allowed this. Reading a feed would have been much more pleasant (not to mention safer for everyone!) if the contents were required to be in plain text.
At least with a cdata tag your being explicitly told “here be dragons”
Whether it's efficient is a far second to whether it successfully imports the data.
Looking at you, WP All Import...
I've found CDATA invaluable, because I can just copy and paste the content from the HTML file to the XML file. I've never used the CDATA terminator characters in a blog post, so that's a non-problem.
The content of that notorious discussion went on and off and on and off for weeks, giving all the netizens of the RSS community blogosphere terrible headaches, with people's entire blogs disappearing and reappearing every second, until it finally reached a flashing point, when Dave Winer humbly conceded that it wasn't the user's fault for being an idiot, and maybe just maybe there was tiny teeny little design flaw in RSS, and it wasn't actually such a great idea to allow HTML tags in RSS titles.
I Wanna Be <![CDATA[
Sung to the tune of “I Wanna Be Sedated”, with apologies to The Ramones.
Twenty-twenty-twenty four escapes to go, I wanna be <![CDATA[
Nothin’ to markup and no where to quo-o-ote, I wanna be <![CDATA[
Just get me through the parser, put me in a node
Hurry hurry hurry before I go inline
I can’t control my syntax, I can’t control my name
Oh no no no no no
Twenty-twenty-twenty four escapes to go….
Just put me in a stylesheet, get me in a namespace
Hurry hurry hurry before I go inline
I can’t control my syntax, I can’t control my name
Oh no no no no no
Twenty-twenty-twenty four escapes to go, I wanna be <![CDATA[
Nothin’ to markup and no where to quo-o-ote, I wanna be <![CDATA[
Just get me through the parser, put me in a node
Hurry hurry hurry before I go loco
I can’t control my syntax I can’t control my name
Oh no no no no no
Twenty-twenty-twenty escapaes to go…
Just get me through the parser…
Ba-ba-bamp-ba ba-ba-ba-bamp-ba I wanna be <![CDATA[
Ba-ba-bamp-ba ba-ba-ba-bamp-ba I wanna be <![CDATA[
Ba-ba-bamp-ba ba-ba-ba-bamp-ba I wanna be <![CDATA[
Ba-ba-bamp-ba ba-ba-ba-bamp-ba I wanna be <![CDATA[