www.webdeveloper.com
Results 1 to 6 of 6

Thread: Creating line break in xml for RSS feed

  1. #1
    Join Date
    Mar 2009
    Posts
    3

    Question Creating line break in xml for RSS feed

    Hello,

    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"?>
    <rss version="2.0">
    <channel>
    <title>title text </title>
    <link>link text</link>
    <description> Description Text</description>
    <language>en-us</language>
    <copyright>Quotes And Poem (c) 2004 - 2007</copyright>
    <item>
    <title>Poem Title</title>
    <link>Poem Link</link>
    <description>
    Poem Text (HOW DO I CREATE LINE BREAKS FOR EACH LINE OF THE POEM)
    </description>
    <pubDate> Publication Date </pubDate>
    <guid isPermaLink="true">Text here</guid>
    </item>
    </channel>
    </rss>

    I appreciate any help in resolving this issu.
    Thanks
    Iffili

  2. #2
    Join Date
    Aug 2006
    Posts
    1,908
    Have you tried it like this:

    Code:
    <description><![CDATA[
    <p>There once was a man from nantucket<br>
    Who kept all his fish in a bucket</p>
    ]]></description>

  3. #3
    Join Date
    May 2008
    Posts
    381
    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":
    Code:
    <description xml:space="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".

  4. #4
    Join Date
    Mar 2009
    Posts
    3
    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 :

    <description xml:space="preserve">
    He put the belt around my life, -- <br>
    heard the buckle snap... <br>
    .......text continues....
    </description>

    The error given was along the line that br did not match </description> tag
    Thanks
    Iffili

  5. #5
    Join Date
    May 2008
    Posts
    381
    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).

  6. #6
    Join Date
    Mar 2009
    Posts
    3
    Hi rpgfan,

    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.

    http://feeds2.feedburner.com/quotesandpoem/poemoftheday

    Thanks to both of you in providing valuable suggestions.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles