question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for CDATA

See original GitHub issue

This is still the same issue as in #280 but since it is closed I reopen it.

Problem

I need the following XML output:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>My Feed</title>
    <link>http://foo</link>
    <description>My description</description>
    <item>
      <title>item title</title>
      <link>http://bar</link>
      <description><![CDATA[ <hello>world</hello> ]]></description>
    </item>
  </channel>
</rss>

However, I only get ROME to output this:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>My Feed</title>
    <link>http://foo</link>
    <description>My description</description>
    <item>
      <title>item title</title>
      <link>http://bar</link>
      <description>&lt;![CDATA[ &lt;hello&gt;world&lt;/hello&gt; ]]&gt;</description>
    </item>
  </channel>
</rss>

Apparently the CDATA section is ignored and the content of “description” is escaped.

Question Is there any constellation how I can get ROME to produce an RSS V2 feed with an unescaped “description” section? Unfortunately I am implementing a given requirement so it has to be the “description” field.

This is my current code:

Channel feed = new Channel();
feed.setFeedType("rss_2.0");
feed.setTitle("My Feed");
feed.setDescription("My description");
feed.setLink("http://foo");
feed.setUri("http://feed-address");

Item item = new Item();
item.setTitle("item title");
item.setLink("http://bar");
Description description = new Description();
description.setType("application/xml");
description.setValue("<![CDATA[ <hello>world</hello> ]]>");
item.setDescription(description);

feed.setItems(Arrays.asList(item));

System.out.println(new WireFeedOutput().outputString(feed));

Many thanks for your support.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
PatrickGotthardcommented, Jun 13, 2020

Hi @samba2,

ROME does currently not support unescaped CDATA sections. The reasons are already explained the given issue #280. We currently have no resources to implement this feature.

If you don’t need other functionalities of ROME other than generating an RSS 2.0 feed, you have the possibility to use any XML library for that purpose at the moment.

I hope this helps. I’ll leave this issue open, maybe we will find some time to add CDATA support.

Regards, Patrick

0reactions
ptimcommented, Oct 8, 2021

@SvenWoltmann I came here due to smart news, too; here’s my dirty solution:

import org.jdom2.CDATA;

// ...

public void generateAnalytics(final SmartNewsFeedEntryModuleImpl snf, final Element element) {
        if (snf.getGaProperty() != null
                && snf.getGaCookieDomain() != null
                && snf.getPageUrl() != null
        ) {
            String gaScript = "<script>"
                    + "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){"
                    + "(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),"
                    + "m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)"
                    + "})(window,document,'script','//www.google-analytics.com/analytics.js','ga');"
                    + "ga('create', '%s', '%s');"
                    + "ga('require', 'displayfeatures');"
                    + "ga('set', 'referrer', 'http://www.smartnews.com/');"
                    + "ga('send', 'pageview', '%s');"
                    + "</script>";

            gaScript = String.format(
                    gaScript,
                    snf.getGaProperty(),
                    snf.getGaCookieDomain(),
                    snf.getPageUrl()
            );

            Element snfEl = new Element("analytics", NAMESPACE);
            snfEl.addContent(new CDATA(gaScript));

            element.addContent(snfEl);
        }
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Technical Support - CData Software
We provide premium technical support via email and phone. All Premium emails and calls are given priority over any standard support questions. Responses...
Read more >
CData Drivers
Robust connectivity: dynamic metadata, caching, replication, remoting, query pushdown, & more. Data Sources. Connect your BI, Analytics ...
Read more >
CData Connect | Getting Started
We pack as many help resources into our products as we can and we make that same valuable information online. · ADO.NET Driver...
Read more >
Online Help Files - CData Software
Online Help Files. Each online help file offers extensive overviews, samples, walk-throughs, and API documentation. ... Google Ad Manager. Google Ads.
Read more >
REST Easy with CData Drivers
The CData Drivers for REST provide standards-based access to REST resources by modeling local and remote data as relational tables, views, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found