Creating line break in xml for RSS feed
I am new to xml and my issue pertains to an RSS feed that I am passing in an xml file.
The RSS feed http://feeds2.feedburner.com/quotesandpoem/poemoftheday
displays a poem every day.
The issue that I have is that I cannot figure out how to create new
lines for each line of my poem. The entire poem text is garbled into
a single line in the feed.
The poem text is under the xml tag <description> as follows:
<description> poem text </description>. If I put any of the typical html tags in there to create the new line it does not work. And I am not sure what xml tags I should use so that the poem is formatted in multiple lines based on the poem text flow.
The code template for the xml fed to RSS feed is as follows:
<?xml version="1.0" encoding="windows-1252"?>
<title>title text </title>
<description> Description Text</description>
<copyright>Quotes And Poem (c) 2004 - 2007</copyright>
Poem Text (HOW DO I CREATE LINE BREAKS FOR EACH LINE OF THE POEM)
<pubDate> Publication Date </pubDate>
<guid isPermaLink="true">Text here</guid>
I appreciate any help in resolving this issu.
Have you tried it like this:
<p>There once was a man from nantucket<br>
Who kept all his fish in a bucket</p>
Using CDATA still won't preserve line breaks, and not all RSS aggregators understand XHTML elements like p and br.
Try using @xml:space with a value of "preserve":
From section 2.10 (white-space handling) of the XML recommendation:
In editing XML documents, it is often convenient to use "white space" (spaces, tabs, and blank lines) to set apart the markup for greater readability. Such white space is typically not intended for inclusion in the delivered version of the document. On the other hand, "significant" white space that should be preserved in the delivered version is common, for example in poetry and source code.
A special attribute named xml:space may be attached to an element to signal an intention that in that element, white space should be preserved by applications. In valid documents, this attribute, like any other, MUST be declared if it is used. When declared, it MUST be given as an enumerated type whose values are one or both of "default" and "preserve".
Thanks for the replies,
rpgfan3233 I tried your method, but there must be something that I missed as the RSS feed gave me an error.
What I tried (along with a few different permutations) was :
He put the belt around my life, -- <br>
heard the buckle snap... <br>
The error given was along the line that br did not match </description> tag
You shouldn't need a <br> when you use xml:space, and <br> is HTML anyway.
You would need to use the XHTML version <br/> if you want it to be parsed properly. On the other hand, <br/> might not work anyway. As I mentioned, XHTML isn't recognized by all RSS aggregators, even if you qualify it with the proper namespace. Take out the <br> tags and see if xml:space fixed your issue. If it didn't, I suppose you could try using <br/>, though it technically wouldn't be "valid" RSS, and not all aggregators will understand what to do with it (some will even fail to parse the feed since <br/> is unrecognised).
I tried <description xml:space="preserve"> in multiple ways including no html tag, <br>, <br />, etc - but with no luck.
However, I tried the CDATA that tracknut mentioned and it appears to work its magic - atleast with google reader, my yahoo and feedburner.
Thanks to both of you in providing valuable suggestions.
Users Browsing this Thread
There are currently 2 users browsing this thread. (0 members and 2 guests)