tag:help-archives.hannonhill.com,2010-02-09:/discussions/velocity-formats/250-velocity-and-cdata-in-rss-feedCascade CMS: Discussion 2013-08-20T03:43:14Ztag:help-archives.hannonhill.com,2010-02-09:Comment/189265152012-09-21T17:42:56Z2012-09-21T17:42:56ZVelocity and CDATA in RSS Feed<div><p>I should say I found I can do this in XSLT by disabling the
escaping of the output of the summary field</p>
<p><code><xsl:value-of disable-output-escaping="yes"
select="atom:summary"/></code></p>
<p>but I can see no way to do something similar in Velocity.</p></div>erikgtag:help-archives.hannonhill.com,2010-02-09:Comment/189265152012-09-21T18:56:23Z2012-09-21T18:56:23ZVelocity and CDATA in RSS Feed<div><p>Hi,</p>
<p>I believe the issue is definitely that HTML doesn't know what to
do with the CDATA tags. Not quite sure, but for some reason this
works (can't guarantee it always will):</p>
<pre>
<code>#set ($feed = $_XPathTool.selectSingleNode($contentRoot,"/feed"))
#set ($entries = $feed.getChildren())
#if ( $entries.size() > 0 )
#foreach($entry in $entries)
#if ( $entry.getName() == "entry" )
#set ( $elements = $entry.getChildren() )
#foreach ( $e in $elements )
#if ( $e.getName() == "title" )
#set ( $title = $e )
#end
#if ( $e.getName() == "link" )
#set ( $link = $e )
#end
#if ( $e.getName() == "published" )
#set ( $published = $e )
#end
#if ( $e.getName() == "author" )
#set ( $author = $e )
#end
#if ( $e.getName() == "summary" )
#set ( $summary = $e )
#end
#end
<div class="newsPost">
<h4><a href="$_EscapeTool.xml($link.value)">$_EscapeTool.xml($title.value)</a></h4>
<span class="cite">from $_EscapeTool.xml($author.value)</span>
$summary.value
</div>
#end
#end
#end</code>
</pre>
<p>Also wanted to note, instead of looping through
<code>$entry.getChildren()</code>, you could do:</p>
<pre>
<code>$entry.getChild('summary').value</code>
</pre></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/189265152012-09-21T20:50:20Z2012-09-21T20:51:19ZVelocity and CDATA in RSS Feed<div><p>Actually, from what I can tell the looping has to occur. The
feed has a namespace (the feed is an atom feed), so the elements
can't be referred to directly like you would in regular XML
constructions. Other discussion topics here regarding XML and atom
feeds have used this looping convention to get around the namespace
issue, and it's the only thing I've found to work. In fact, I've
tried what you mention and it hasn't worked to return the node
elements. Oh do I wish it could, though. :)</p>
<p>As for the $summary.value part, that does not work for me
either, though I imagine it will with the XML snippet I provided
above. I abbreviated it for the example above, but the real content
of the summary field looks more like this:</p>
<pre>
<code><summary type="html">
<![CDATA[<p>
<a href="http://blogs.reed.edu/reed_blogs/the_riffin_griffin/switchboard_5.12.jpg"><img alt="switchboard_5.12.jpg" class="mt-image-left" height="225" src="http://blogs.reed.edu/reed_blogs/the_riffin_griffin/assets_c/2012/05/switchboard_5.12-thumb-300x225-2989.jpg" style="float: left; margin: 0 20px 20px 0;" width="300" /></a></p>
<p>
The <a href="http://reedswitchboard.com/" target="_blank">Reed Switchboard</a> is a volunteer effort aimed at fostering contact between current students and alumni. We&#39;ve partnered with artist Lucy Bellwood &#39;12 to bring you the <a href="http://switchboardhearts2012.tumblr.com/" target="_blank">Switchboard Hearts 2012 project</a>. During <a href="http://reedfayre.reed.edu/" target="_blank">Reunions &#39;12: Reedfayre</a>, Lucy will be on campus taking photos of Reedies and their passions on Saturday, noon to 5 p.m., outside between Old Dorm Block and Eliot.</p>
<p>
<strong>Alumni</strong>: what are you passionate about? If a current student called you, what would you want to talk to them about? Who are the Reedies you&#39;d like to connect with and what are their interests? The photos we take during Reedfayre will be posted online later this summer so that everyone interested in, say, &quot;museums&quot; can learn about their shared interests and connect with each other. &nbsp;Join the photo shoot!</p>
<p>
For more information, send email to&nbsp;<a href="mailto:reedswitchboard@gmail.com">reedswitchboard@gmail.com</a>.</p>
]]></summary></code>
</pre>
<p>Because the contained html contains code like
<code>&nbsp;</code> and such, all I get are errors when
referring to the element by $summary.value. Sorry for not making my
example above more robust.</p>
<p>It seems to me that the SerializerTool is actually escaping the
CDATA code segments so that they show. It would be better if it
just stripped them out, or at least had an option to not escape the
content like XSLT does.</p></div>erikgtag:help-archives.hannonhill.com,2010-02-09:Comment/189265152012-09-21T21:05:14Z2012-09-21T21:05:14ZVelocity and CDATA in RSS Feed<div><p>Oh, for anyone interested, here is the source feed I'm trying to
parse:</p>
<p>
<code>http://blogs.reed.edu/the_riffin_griffin/feed_reunions.xml</code></p></div>erikgtag:help-archives.hannonhill.com,2010-02-09:Comment/189265152012-09-24T14:45:50Z2012-09-24T14:45:50ZVelocity and CDATA in RSS Feed<div><p>HI Erik,</p>
<p>My apologies, I didn't see the entities within the summary.</p>
<p>I'm not seeing a straightforward way to output that content. You
could perhaps encode the HTML using
<code>$_EscapeTool.javascript()</code> (this seems to strip out the
CDATA) and use JavaScript to decode the HTML and append the result
to your listing. I found a few posts by searching something like
<em>javascript html entity decode</em>.</p>
<p>As you stated above, I'm thinking your best bet would be to use
an XSLT Format to output your content.</p>
<p>Hopefully someone else has encountered this situation with
Velocity and will chip in.</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/189265152012-10-18T15:55:31Z2012-10-18T15:55:31ZVelocity and CDATA in RSS Feed<div><p>Hi Erik,</p>
<p>I was going over some older discussions and noticed this one is
still open. Were you able to get your Velocity Format working, or
did you switch to XSLT?</p>
<p>Please feel free to let us know if you have any other
questions.</p>
<p>Thanks.</p></div>Ryan Griffithtag:help-archives.hannonhill.com,2010-02-09:Comment/189265152012-10-18T16:08:42Z2012-10-18T16:08:42ZVelocity and CDATA in RSS Feed<div><p>Thanks for checking in. I ended up abandoning the Velocity
approach and went with XSLT instead. I just couldn't get Velocity
to behave correctly without introducing unnecessary complexity. A
simple XSLT script did the trick.</p>
<p>From what I could see, Velocity lacked the equivalent of XSLT's
disable-output-escaping option, as in the following:</p>
<p><code><xsl:value-of disable-output-escaping="yes"
select="atom:summary"/></code></p>
<p>Velocity has been my script format of choice, but it's not quite
ready for some things. Name spaces and CDATA seem to be its
greatest weaknesses.</p></div>erikgtag:help-archives.hannonhill.com,2010-02-09:Comment/189265152012-10-18T17:25:50Z2012-10-18T17:25:50ZVelocity and CDATA in RSS Feed<div><p>Thank you for the follow up, Erik. Glad to hear you were able to
get an XSLT equivalent working.</p>
<blockquote>
<p>Velocity has been my script format of choice, but it's not quite
ready for some things. Name spaces and CDATA seem to be its
greatest weaknesses.</p>
</blockquote>
<p>I definitely agree, there are some things that XSLT does better
and those two points are two of them</p>
<p>I'm going to go ahead and close this discussion, feel free to
reply or comment to re-open this discussion if you have any
additional questions.</p>
<p>Thanks.</p></div>Ryan Griffith