How to remove tags <! [CDATA []]> with all the text in XML using Hpricot?

I just want the text to be from there with these tags. Does Hrpicot.XML have any methods for this?

+4
source share
3 answers

use element.inner_text instead of #inner_html and delete them for you

+6
source
doc.search("*") do |element| element.swap element.content if element.kind_of? Hpricot::CData end 
+2
source
 doc = Hpricot::XML(open('http://www.cnn.com/.element/ssi/www/auto/2.0/video/xml/most_popular.xml')) (doc/:cnn_video/:video).each do |status| ['tease_txt'].each do |el| puts "#{status.at(el).inner_text}" end end 

Example output (looks like spam, but it's not spam!):

Reno's New Air Crash Show Shows Impact
Teen catches a 800 kg gator
Resume Career Do Not Ask Cancel Creepy Skirts Peepers
A satellite-sized bus to reach Earth ... "DWTS" throws ballroom for the first time
What caused the death of a coach at SeaWorld?
What led to the denial of Troy Davis's pardon?

+1
source

All Articles