# To\_xml :methods generating escaped XML

**URL:** <https://www.ruby-forum.com/t/to-xml-methods-generating-escaped-xml/145981>\
**Category:** Rails\
**Created:** [August 15, 2008, 7:36pm UTC](https://www.ruby-forum.com/t/to-xml-methods-generating-escaped-xml/145981 "2008-08-15T19:36:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![noreaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c67d28/32.png) [@noreaster](https://www.ruby-forum.com/u/noreaster)\
**Post date:** [August 15, 2008, 7:36pm UTC](https://www.ruby-forum.com/t/to-xml-methods-generating-escaped-xml/145981/1 "2008-08-15T19:36:24Z")

</div>

Howdy. Ruby N. here.

I have a couple of methods in one of my models:

def program\_asset  
if promo?  
PromoVersion.find(self[:promo\_vid])  
elsif feature?  
play\_id = self[:play\_id]  
my\_play = Playdate.find(play\_id)  
my\_fid = my\_play[:fid]  
ProductVersionFormat.find(my\_fid)  
else  
logger.fatal "Came across a log item that was neither a promo nor  
a feature: " + self  
end  
end

def program\_asset\_xml  
program\_asset.to\_xml(:skip\_instruct =\> true)  
end

# include the first-level associations.

alias\_method :ar\_to\_xml, :to\_xml  
def to\_xml(options = {})  
default\_methods = [:program\_asset\_xml]  
options[:methods] = (options[:methods] ? options[:methods] +  
default\_methods : default\_methods )  
ar\_to\_xml(options)  
end

Sort of works okay, except here is a snippet of XML that gets returned  
to a browser or client:

…  
\<video\_guide\>\</video\_guide\>  
\<program\_asset\_xml\>  
\<promo\_version\>  
\<anchor\_type\>\</anchor\_type\>  
\<artesia\_did type=“integer”\>\</artesia\_did\>  
…  
\<video\_guide\>N\</video\_guide\>  
\</promo\_version\>  
\</program\_asset\_xml\>  
…

The :include-d program asset’s XML gets converted into an escaped  
string, where the angle brackets have been replaced by \< and \> .  
What am I doing wrong?

Thanks very much in advance for any help, as well as any other  
suggestions you may have!

---

<div class="post-metadata">

**Author:** ![noreaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c67d28/32.png) [@noreaster](https://www.ruby-forum.com/u/noreaster)\
**Post date:** [August 18, 2008, 11:47pm UTC](https://www.ruby-forum.com/t/to-xml-methods-generating-escaped-xml/145981/2 "2008-08-18T23:47:03Z")

</div>

Bump. Why is it that I have to CGI.unescapeHTML the output in order for  
it to appear correct on the client side? CGI.unescapeHTML introduces a  
big performance hit, for some reason (and that could be another issue).
