Forum: Ruby rexml create a tag with literal characters

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Onno F. (Guest)
on 2008-10-22 12:07
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
<u></u> and <b></b>. I want to preserve this, as excel can read these
tags out and format the document. However, the output is as follows:
&lt;u&gt;

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

Thank you, Onno
Robert K. (Guest)
on 2008-10-22 13:17
(Received via mailing list)
2008/10/22 Onno F. <removed_email_address@domain.invalid>:
> tags out and format the document. However, the output is as follows:
> &lt;u&gt;
>
> 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("<root/>")
puts master

# find the node - either way
root = master[1]
root = master.elements['//root']

# parse the sub tree
sub = REXML::Document.new "<some>test data</some>"

# add the subtree
root.add sub

# see what we got
puts master

Kind regards

robert
This topic is locked and can not be replied to.