# How to get builder 2.0 to escape attributes in rxml

**URL:** <https://www.ruby-forum.com/t/how-to-get-builder-2-0-to-escape-attributes-in-rxml/98429>\
**Category:** Rails\
**Created:** [July 14, 2006, 6:27pm UTC](https://www.ruby-forum.com/t/how-to-get-builder-2-0-to-escape-attributes-in-rxml/98429 "2006-07-14T18:27:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![digitalpodcast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/278dde/32.png) [@digitalpodcast](https://www.ruby-forum.com/u/digitalpodcast)\
**Post date:** [July 14, 2006, 6:27pm UTC](https://www.ruby-forum.com/t/how-to-get-builder-2-0-to-escape-attributes-in-rxml/98429/1 "2006-07-14T18:27:31Z")

</div>

I am using rxml to produce opml files and need to escape ampersands in  
the attributes.

builder 2.0 docs found at [http://builder.rubyforge.org/](http://builder.rubyforge.org/) show the  
following

xml = Builder::XmlMarkup.new  
xml.sample(:escaped=\>“This&That”, :unescaped=\>:“Here&There”)  
xml.target! =\>

I tried to install and repeat this result, but attributes are not  
escaping

Here is the gem install and the attempt to test escaping attributes:

C:\rails\>“c:\ruby\bin\ruby.exe” “c:\ruby\bin\gem” install builder  
–version 2.0

Attempting local installation of ‘builder’  
Local gem file not found: builder\*.gem  
Attempting remote installation of ‘builder’  
Successfully installed builder-2.0.0  
Installing RDoc documentation for builder-2.0.0…

C:\rails\>cd buildertest

C:\rails\buildertest\>ruby script/console  
Loading development environment.

> > xml = Builder::XmlMarkup.new  
> > =\>   
> > xml.sample(:escaped=\>“this & that”)  
> > =\> “\<sample escaped="this & that"/\>”  
> > exit

Does anybody know what could be wrong?

---

<div class="post-metadata">

**Author:** ![digitalpodcast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/278dde/32.png) [@digitalpodcast](https://www.ruby-forum.com/u/digitalpodcast)\
**Post date:** [July 18, 2006, 9:02pm UTC](https://www.ruby-forum.com/t/how-to-get-builder-2-0-to-escape-attributes-in-rxml/98429/2 "2006-07-18T21:02:47Z")

</div>

Alex,  
Alex,

Use builder’s \<\< operator to append text without escaping markup.

Example  
xml.\<\< ‘This&That’

See also my blog post on using this in rxml templates:  
[http://www.depixelate.com/articles/2006/07/18/quick-tip-rails-partials-in-rss-feeds](http://www.depixelate.com/articles/2006/07/18/quick-tip-rails-partials-in-rss-feeds)

See also the docs:  
[http://caboo.se/doc/classes/Builder/XmlBase.html#M004081](http://caboo.se/doc/classes/Builder/XmlBase.html#M004081)

Hope this helps,  
Zack

---

<div class="post-metadata">

**Author:** ![digitalpodcast](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/278dde/32.png) [@digitalpodcast](https://www.ruby-forum.com/u/digitalpodcast)\
**Post date:** [July 22, 2006, 9:56pm UTC](https://www.ruby-forum.com/t/how-to-get-builder-2-0-to-escape-attributes-in-rxml/98429/3 "2006-07-22T21:56:51Z")

</div>

Thanks for the reponse Zack, but my problem is the opposite. I need  
Builder to escape the markup and it’s not doing it for some reason.

When I use buidler

this is what I get

C:\rails\buildertest\>ruby script/console  
Loading development environment.

> > xml = Builder::XmlMarkup.new  
> > =\>   
> > xml.sample(:escaped=\>“this & that”)  
> > =\> “\<sample escaped="this & that"/\>”  
> > exit

If you look at the markup you can see that what is supposed to be  
escaped is not.

I am running builder 2.0 and the specs say that it should escape  
attributes, but for some reason it doesn’t seem to be working.

Any idea what might be wrong?

Zack C. wrote:

> Alex,  
> Alex,
> 
> Use builder’s \<\< operator to append text without escaping markup.
> 
> Example  
> xml.\<\< ‘This&That’
> 
> See also my blog post on using this in rxml templates:  
> [http://www.depixelate.com/articles/2006/07/18/quick-tip-rails-partials-in-rss-feeds](http://www.depixelate.com/articles/2006/07/18/quick-tip-rails-partials-in-rss-feeds)
> 
> See also the docs:  
> [http://caboo.se/doc/classes/Builder/XmlBase.html#M004081](http://caboo.se/doc/classes/Builder/XmlBase.html#M004081)
> 
> Hope this helps,  
> Zack
