
Untitled
By: a guest on
May 2nd, 2012 | syntax:
None | size: 1.27 KB | hits: 17 | expires: Never
How do I unescape HTML tags from XML?
<?xml version="1.0" encoding="UTF-8"?>n<response>n <data>n <publisher_share_percent>0.0</publisher_share_percent>n <detailed_description><b>this is the testing detailed</b> </detailed_description>n <title>Only £5.00. food (Regular £50.00 / 90% discount)</title>n </data>n <request_id>ed96dd50-3127-012f-3e93-042b2b8686e6</request_id>n <message>The resource has been created successfully.</message>n <status>201</status>n</response>n
require 'cgi'
CGI::unescapeHTML("Usage: foo "bar" <baz>")
# => "Usage: foo "bar" <baz>"
require 'nokogiri'
xml = <<EOT
<?xml version="1.0" encoding="UTF-8"?>
<response>
<data>
<publisher_share_percent>0.0</publisher_share_percent>
<detailed_description><b>this is the testing detailed</b> </detailed_description>
<title>Only £5.00. food (Regular £50.00 / 90% discount)</title>
</data>
<request_id>ed96dd50-3127-012f-3e93-042b2b8686e6</request_id>
<message>The resource has been created successfully.</message>
<status>201</status>
</response>
EOT
doc = Nokogiri::XML(xml)
puts doc.at('detailed_description').text
puts doc.at('title').text
ruby ~/Desktop/test2.rb
<b>this is the testing detailed</b>
Only £5.00. food (Regular £50.00 / 90% discount)