node-rss icon indicating copy to clipboard operation
node-rss copied to clipboard

No CDATA

Open tmshv opened this issue 11 years ago • 12 comments

Is it possible to create XML without a CDATA?

tmshv avatar Feb 09 '14 14:02 tmshv

It should be, what does your code look like?

dylang avatar Feb 09 '14 14:02 dylang

console.log(new RSS({
    title: "hello"
}).xml("\t"));
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
        <title><![CDATA[hello]]></title>
        <description><![CDATA[hello]]></description>
        <link>http://github.com/dylan/node-rss</link>
        <generator>RSS for Node</generator>
        <lastBuildDate>Sun, 09 Feb 2014 15:57:10 GMT</lastBuildDate>
    </channel>
</rss>

tmshv avatar Feb 09 '14 16:02 tmshv

Pull request: https://github.com/dylang/node-rss/pull/28

tmshv avatar Feb 09 '14 17:02 tmshv

Thank you for the pull request!

I replied quickly on my phone without looking carefully and thought you were asking about node-xml, not this one.

I put those in ![CDATA because I wasn't sure if the text would be valid for XML. Do you think there's a way to check the string and automatically wrap with ![CDATA only when needed?

dylang avatar Feb 09 '14 20:02 dylang

According to http://www.w3.org/TR/REC-xml/#syntax it looks like CDATA is only needed when the string has <, >, or &. What do you think checking for those strings and only using CDATA when one of them is found?

dylang avatar Feb 09 '14 20:02 dylang

Actually xml module making this work

var xml = require("xml");
console.log(xml({hello:"lol"})); //<hello>lol</hello>
console.log(xml({hello:"<lol>"})); //<hello>&lt;lol&gt;</hello>

tmshv avatar Feb 10 '14 14:02 tmshv

Is this and #28 still needed?

dylang avatar Sep 26 '14 22:09 dylang

Right now I'm not working on a project which used it, but why not?

tmshv avatar Sep 27 '14 19:09 tmshv

If nobody is having problems with the current code I'd rather not change the code which could potentially introduce new problems.

dylang avatar Sep 27 '14 22:09 dylang

Sounds like a death sentence.

tmshv avatar Sep 28 '14 12:09 tmshv

I would be in favour of making this change, it seems unnecessary to have CDATA everywhere when it is only required if the string contains one of three characters, which is a rarity. It's definitely aesthetics rather than having a true technical grounding, but when you compare an RSS feed from Ghost to one from another platform ours look really messy and we are really keen to do much better in this area.

ErisDS avatar Mar 22 '15 14:03 ErisDS

bump/update/eta?

cekvenich avatar Mar 30 '18 15:03 cekvenich