Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7928307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:41:48+00:00 2026-06-03T19:41:48+00:00

Using Rails 3 I am consuming an XML feed generated in drupal or something.

  • 0

Using Rails 3 I am consuming an XML feed generated in drupal or something. The tags it gives me look like:

<body><![CDATA[&#60;p&#62;This is a title&#60;br /&#62;A subheading&#60;/p&#62;]]></body>

So the intention is that this should really look like:

<p>This is a title<br />A subheading</p>

Which could then be rendered in a view using <%= @mystring.html_safe %> or <%= raw @mystring %> or something. The trouble is that rendering the string in this way will simply convert substrings like &#60; into the < character. I need a sort of double raw or double unencode to first deal with the chr and then render the tags as html safe.

Anyone know of anything like:

<%= @my_double_safed_string.html_safe.html_safe %>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:41:49+00:00Added an answer on June 3, 2026 at 7:41 pm

    I don’t think this is valid XML – they’ve sort of escaped the text twice in two different ways, by using entities and cdata. Still, you can parse it using nokogiri for example:

    require 'nokogiri'
    
    xml = Nokogiri::XML.parse "<body><![CDATA[&#60;p&#62;This is a title&#60;br /&#62;A subheading&#60;/p&#62;]]></body>"
    text = Nokogiri::XML.parse("<e>#{xml.text}</e>").text
    #=> text = "<p>This is a title<br />A subheading</p>"
    

    Seeing as this drupal site is spewing crazy double escaped xml, I’d be inclined to even use a regexp. Hacks to solve a problem hacks created? IDK. Regardless:

    xml.text
    #=> "&#60;p&#62;This is a title&#60;br /&#62;A subheading&#60;/p&#62;"
    xml.text.gsub(/\&\#([0-9]+);/) { |i| $1.to_i.chr }
    #=> "<p>This is a title<br />A subheading</p>"
    

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Rails, I would like to add: <span class='req'>&bull;</span> within my <label> tags in
Using Rails 3.2.0 with haml and sass: I Would like to link an external
I am using Ruby on Rails 3 and I would like to start to
Using Rails 3.1.1. & 'rails3-jquery-autocomplete' I think this question should be quite simple for
Using Rails 3.1.1, I'm getting occasional errors in production where it seems like the
This one might be a little confusing. I'm using AMCharts with rails. Amcharts comes
Using Rails 3.1.3 with Ruby 1.9.3p0. I've discovered that by default, Rails does not
Using Rails 3.1.3 and Ruby 1.9.3. I want to give the user a list
Using RAILS 2.2 Hello I am having an issue where my dates are being
Using Rails ActiveRecord, am wanting to calculate the time between two datetime fields within

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.