# Rexml create a tag with literal characters

**URL:** <https://www.ruby-forum.com/t/rexml-create-a-tag-with-literal-characters/151510>\
**Category:** Ruby\
**Created:** [October 22, 2008, 10:07am UTC](https://www.ruby-forum.com/t/rexml-create-a-tag-with-literal-characters/151510 "2008-10-22T10:07:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ogtfaber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e0b2c6/32.png) [@ogtfaber](https://www.ruby-forum.com/u/ogtfaber)\
**Post date:** [October 22, 2008, 10:07am UTC](https://www.ruby-forum.com/t/rexml-create-a-tag-with-literal-characters/151510/1 "2008-10-22T10:07:40Z")

</div>

I’m having a problem finding out how to parse literal characters into a  
new tag using rexml. I’m creating an excel xml document using rexml:  
xml.instruct! :xml, :version=\>“1.0”, :encoding=\>“UTF-8”

In the document, I’m creating a “Data” tag, and parsing the content of  
the variable “content\_line” in it:  
xml.Data content\_line, ‘ss:Type’ =\> ‘String’

The thing is that the data in “content\_line” contains simple tags like  
 and . I want to preserve this, as excel can read these  
tags out and format the document. However, the output is as follows:  
\<u\>

Is there any way I can prevent this encoding from happening? So far I  
was not able to find the answer.

Thank you, Onno

---

<div class="post-metadata">

**Author:** ![ogtfaber](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/e0b2c6/32.png) [@ogtfaber](https://www.ruby-forum.com/u/ogtfaber)\
**Post date:** [October 22, 2008, 11:17am UTC](https://www.ruby-forum.com/t/rexml-create-a-tag-with-literal-characters/151510/2 "2008-10-22T11:17:59Z")

</div>

2008/10/22 Onno F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> tags out and format the document. However, the output is as follows:  
> \<u\>
> 
> Is there any way I can prevent this encoding from happening? So far I  
> was not able to find the answer.

XML parse the string yourself and add those nodes to the document.  
Example:

require ‘rexml/document’

# create the doc

master = REXML::Document.new(“”)  
puts master

# find the node - either way

root = master[1]  
root = master.elements[‘//root’]

# parse the sub tree

sub = REXML::Document.new “test data”

# add the subtree

root.add sub

# see what we got

puts master

Kind regards

robert
