# Source code to XML

**URL:** <https://www.ruby-forum.com/t/source-code-to-xml/143742>\
**Category:** Ruby\
**Created:** [July 22, 2008, 12:23pm UTC](https://www.ruby-forum.com/t/source-code-to-xml/143742 "2008-07-22T12:23:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fantomknight10](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/94ad74/32.png) [@fantomknight10](https://www.ruby-forum.com/u/fantomknight10)\
**Post date:** [July 22, 2008, 12:23pm UTC](https://www.ruby-forum.com/t/source-code-to-xml/143742/1 "2008-07-22T12:23:40Z")

</div>

I need to generate DocBook ProgramListing xincludes from a source code  
file.  
How can I escape characters that is not valid in text : \< \> " &

---

<div class="post-metadata">

**Author:** ![fantomknight10](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/94ad74/32.png) [@fantomknight10](https://www.ruby-forum.com/u/fantomknight10)\
**Post date:** [July 22, 2008, 2:20pm UTC](https://www.ruby-forum.com/t/source-code-to-xml/143742/2 "2008-07-22T14:20:36Z")

</div>

On Jul 22, 6:17 pm, Tommy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I need to generate DocBook ProgramListing xincludes from a source code  
> file.  
> How can I escape characters that is not valid in text : \< \> " &
> 
> * * *
> 
> This sig is dedicated to the advancement of Nuclear Power  
> Tommy N.  
> removed\_email\_address@domain.invalid

irb(main):020:0\> require ‘rexml/text’  
=\> true  
irb(main):021:0\> REXML::Text.normalize(“Some & text \< foo \> " bar”)  
=\> “Some & text \< foo \> " bar”

this may help

---

<div class="post-metadata">

**Author:** ![fantomknight10](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/94ad74/32.png) [@fantomknight10](https://www.ruby-forum.com/u/fantomknight10)\
**Post date:** [July 22, 2008, 2:15pm UTC](https://www.ruby-forum.com/t/source-code-to-xml/143742/3 "2008-07-22T14:15:54Z")

</div>

On Jul 22, 6:17 pm, Tommy N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I need to generate DocBook ProgramListing xincludes from a source code  
> file.  
> How can I escape characters that is not valid in text : \< \> " &
> 
> * * *
> 
> This sig is dedicated to the advancement of Nuclear Power  
> Tommy N.  
> removed\_email\_address@domain.invalid

require ‘rexml/text’  
REXML::Text.normalize(“Some & text \< foo \> " bar”)  
==\> “Some & text \< foo \> " bar”

i think this may help you
