Say I have a string that represents an XML element that I want to
embed into a REXML::Element, how would I do this?
For example, if I have:
xhtml_elt = REXML::Element.new( ‘xhtml’ )
xhtml_string = “
foo bar
”
Is there a way I could get to:
puts xhtml_elt.to_s
=>
foo bar
Francis
I’m no expert, but after looking at the REXML source, I don’t think this
is possible without changing the REXML code itself. I tried:"
xhtml_elt = REXML::Element.new(‘xhtml’, nil, {:raw=>:all})
xhtml_elt.text = '
foo bar
"
but the second line raises an Illegal character ‘<’ in raw string blah
blah blah. There don’t seem to be any options to avoid this. You
probably don’t want to do this, but you could have the string parsed and
the correct REXML elements can be created. Sorry I couldn’t help more.
···
On Thu, Feb 05, 2004 at 09:40:02AM +0900, Francis Hwang wrote:
Say I have a string that represents an XML element that I want to
embed into a REXML::Element, how would I do this?
For example, if I have:
xhtml_elt = REXML::Element.new( ‘xhtml’ )
xhtml_string = “
foo bar
”
Is there a way I could get to:
puts xhtml_elt.to_s
=>
foo bar
–
Zachary P. Landau kapheine@hypa.net
GPG: gpg --recv-key 0x24E5AD99 | http://kapheine.hypa.net/kapheine.asc
xhtml_elt << REXML::Document.new(xhtml_string).elements[1]
puts xhtml_elt.to_s
-austin
···
On Thu, 5 Feb 2004 09:40:02 +0900, Francis Hwang wrote:
Say I have a string that represents an XML element that I want to embed
into a REXML::Element, how would I do this?
For example, if I have:
xhtml_elt = REXML::Element.new( ‘xhtml’ )
xhtml_string = “
foo bar
”
Is there a way I could get to:
puts xhtml_elt.to_s
=>
foo bar
–
austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2004.02.05
* 12.11.43
sera@fhwang.net (Francis Hwang) wrote in message news:7b561b93.0402041638.4ede5c53@posting.google.com…
Say I have a string that represents an XML element that I want to
embed into a REXML::Element, how would I do this?
For example, if I have:
xhtml_elt = REXML::Element.new( ‘xhtml’ )
xhtml_string = “
foo bar
”
Is there a way I could get to:
puts xhtml_elt.to_s
=>
foo bar
Francis
Oh, for Pete’s sake. All I had to do was use REXML::Document#root.
irb(main):001:0> require ‘rexml/document’
=> true
irb(main):002:0> string = “
foo bar
”
=> “
foo bar
”
irb(main):003:0> REXML::Document.new( string ).root.to_s
=> “
foo bar
”