ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Problem encoding non-ASCII characters in XML for RSS Feeds

August 17, 2007 11:34am

Subscribe [2]
  • #1 / Aug 17, 2007 11:34am

    P.J.

    158 posts

    I am using exp:encode tag to encode both my titles and contents for the RSS and ATOM feeds, and i notice that certains characters are not displayed properly.

    For example,

    This is a feed & a test

    becomes

    This is a feed & a test

    how do i fix this? also, when should i be using glossary tags like:

    & lt; & gt; ©

    instead of just the regular characters (typed in using ALT+number)?

  • #2 / Aug 17, 2007 12:12pm

    Lisa Wess

    20502 posts

    Well, that is correctly, turning an ampersand into its entity makes it validate.  Why is this a problem for you? I’m not quite following what the issue is.

  • #3 / Aug 17, 2007 12:16pm

    Ingmar

    29245 posts

    As Lisa said, this (one of) the point(s) of using {exp:encode} in the first place.

  • #4 / Aug 17, 2007 12:46pm

    P.J.

    158 posts

    oh, i see,

    what i use the built-in feed readers in IE or Firefox, i thought something is wrong when i see “& amp;” instead of the “&” sign.

  • #5 / Aug 17, 2007 12:47pm

    Lisa Wess

    20502 posts

    Those should be converting the entities to their appropriate representation.  Do you have a link to the feed?

  • #6 / Aug 17, 2007 2:24pm

    P.J.

    158 posts

    ok, i have discovered why that is the case,

    right now, i am using

    <title>{exp:xml_encode}{title}{/exp:xml_encode}</title>

    when i review the actual code for the page, i am getting,

    <title>This is a blog &amp; test</title>

    there is a double amp;. how do i fix this?

  • #7 / Aug 17, 2007 2:27pm

    Lisa Wess

    20502 posts

    Ah, yes. You don’t want to ues that plugin in the title element of your page, only in the content area.

  • #8 / Aug 17, 2007 2:29pm

    P.J.

    158 posts

    huh, lisa?

    i am following the EEDoc here:

    http://expressionengine.com/templates/source/category/feeds/

    can you clarify what do mean? what code should i use then for title? if i don’t use the xml_encode tag, what problem with non-standard characters may i expect in the translation?

  • #9 / Aug 17, 2007 2:34pm

    Lisa Wess

    20502 posts

    Ah, my apologies.  I lost track for a second there and thought we were on an HTML page.

    What is the actual title for the particular entry in question?

  • #10 / Aug 17, 2007 2:42pm

    P.J.

    158 posts

    the feed i am developing is an internal site, so i cannot give you an URL to see yet without publishing publicly.

    i removed the xml_encode tag, and it solved the problem. what options in EE can i go to check on this? perhaps i am encoding it wrongly. my EE system is set to use UTF-8.

  • #11 / Aug 17, 2007 2:43pm

    Lisa Wess

    20502 posts

    Well, can you tell me the title? I’m curious what the source is, to see if we can spot a problem there. Also, can you paste your entire template?

  • #12 / Aug 17, 2007 2:49pm

    P.J.

    158 posts

    lisa,

    the title is Travel & Adventure

    here is part of the code (i will remove it after you are done with it):

    {assign_variable:master_weblog_name="blog1"}
    {exp:rss:feed weblog="{master_weblog_name}"}
    
    <?xml version="1.0" encoding="{encoding}"?>
    <rss version="2.0"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
        xmlns:admin="http://webns.net/mvcb/"
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns:content="http://purl.org/rss/1.0/modules/content/">
    
        <channel>
        
        <title>{exp:xml_encode}{site_name}{/exp:xml_encode}</title>
        <link>{weblog_url}</link>
        <description>Test</description>
        <dc:language>{weblog_language}</dc:language>
        <dc:creator>{site_name}</dc:creator>
        <dc:rights>Copyright {gmt_date format="%Y"}</dc:rights>
        <dc:date>{gmt_date format="%Y-%m-
T;%H:%i:%s%Q"}</dc:date>
        <admin:generatorAgent rdf:resource="http://www.adventureclassicgaming.com/" >
        
    {exp:weblog:entries weblog="{master_weblog_name}" limit="15" rdf="off" dynamic_start="on" disable="member_data|pagination|trackbacks"}
        <item>
          <title>{title}</title>
          <link>{exp:xml_encode}{permalink=site/blog}{/exp:xml_encode}</link>
          <description><![CDATA[{exp:trunchtml chars="400" inline="…"}{body}{/exp:trunchtml}]]></description>
          <dc:subject>{exp:xml_encode}{categories backspace="1"}{category_name}, {/categories}{/exp:xml_encode}</dc:subject>
          <content:encoded><![CDATA[{exp:trunchtml chars="400" inline="…"}{body}{/exp:trunchtml}]]></content:encoded>
          <dc:date>{gmt_entry_date format="%Y-%m-
T;%H:%i:%s%Q"}</dc:date>
        </item>
    {/exp:weblog:entries}
        
        </channel>
    </rss>
    
    {/exp:rss:feed}

    you will see that for now i remove the xml_encode from the title, which otherwise will recreate the problem.

  • #13 / Aug 17, 2007 2:53pm

    Lisa Wess

    20502 posts

    Is it just me, or are you missing the opening exp:rss:feed tag?

    If you use just the plain, default RSS template, does the same problem occur?

  • #14 / Aug 17, 2007 2:57pm

    P.J.

    158 posts

    my bad, i did not copy the first two lines.

    i have edited my code above. the exp:rss is there.

    [new info]
    i tested it with the default EE RSS templates, changing only the weblog name and variable i used, and the amp sign still is a problem.

  • #15 / Aug 17, 2007 3:02pm

    Lisa Wess

    20502 posts

    Were you able to test this with a purely default template, with just your short-name changed?  Also, what version and build of EE are you on?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases