# Adding any \<text/\> to a rexml doc (bump)

**URL:** <https://www.ruby-forum.com/t/adding-any-text-to-a-rexml-doc-bump/66769>\
**Category:** Ruby\
**Created:** [December 15, 2005, 7:58pm UTC](https://www.ruby-forum.com/t/adding-any-text-to-a-rexml-doc-bump/66769 "2005-12-15T19:58:28Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 15, 2005, 7:58pm UTC](https://www.ruby-forum.com/t/adding-any-text-to-a-rexml-doc-bump/66769/1 "2005-12-15T19:58:28Z")

</div>

is there know way to do this

require “rexml/document”

include REXML

Text::new " i \< know & what i’m doing "

it seems not…

-a

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 16, 2005, 3:05am UTC](https://www.ruby-forum.com/t/adding-any-text-to-a-rexml-doc-bump/66769/2 "2005-12-16T03:05:37Z")

</div>

On Fri, 16 Dec 2005, Patrick G. wrote:

> > it seems not…
> 
> I am not sure, what you want to do, but perhaps
> 
> Text.unnormalize(" i \< know & what i’m doing ") is the answer?
> 
> REXML won’t let this into the element hierarchy, afaik.

it will - you just have to trick it:

element.text =  
::REXML::Text::new(  
string\_we\_want\_untouched,  
respect\_whitespace=true,  
parent=nil,  
raw=true,  
entity\_filter=nil,  
illegal=%r/.^/m # match nothing!  
)

sean, if you’re reading this a feature in the api to allow this would be  
great.

cheers.

-a

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 16, 2005, 12:13am UTC](https://www.ruby-forum.com/t/adding-any-text-to-a-rexml-doc-bump/66769/3 "2005-12-16T00:13:54Z")

</div>

Hi,

> is there know way to do this
> 
> require “rexml/document”
> 
> include REXML
> 
> Text::new " i \< know & what i’m doing "
> 
> it seems not…

I am not sure, what you want to do, but perhaps

Text.unnormalize(" i \< know & what i’m doing ") is the answer?

REXML won’t let this into the element hierarchy, afaik.

Patrick

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 16, 2005, 4:27am UTC](https://www.ruby-forum.com/t/adding-any-text-to-a-rexml-doc-bump/66769/4 "2005-12-16T04:27:08Z")

</div>

On 2005.12.16 03:57, removed\_email\_address@domain.invalid wrote:

> Text::new " i \< know & what i’m doing "
> 
> it seems not…

Perhaps it is time to try Builder or htree? 🙂

> -a

E

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 16, 2005, 5:36am UTC](https://www.ruby-forum.com/t/adding-any-text-to-a-rexml-doc-bump/66769/5 "2005-12-16T05:36:17Z")

</div>

On Dec 15, 2005, at 5:47 PM, removed\_email\_address@domain.invalid wrote:

> > > Text::new " i \< know & what i’m doing "
> 
> sean, if you’re reading this a feature in the api to allow this  
> would be great.
> 
> cheers.
> 
> -a

Ahh thats what the non matching regex was for…

Cheers-

-Ezra Z.  
WebMaster  
Yakima Herald-Republic Newspaper  
removed\_email\_address@domain.invalid  
509-577-7732

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 16, 2005, 6:39am UTC](https://www.ruby-forum.com/t/adding-any-text-to-a-rexml-doc-bump/66769/6 "2005-12-16T06:39:24Z")

</div>

On Fri, 16 Dec 2005, Eero S. wrote:

> > Text::new " i \< know & what i’m doing "
> > 
> > it seems not…
> 
> Perhaps it is time to try Builder or htree? 🙂

i can’t stand the builder api. htree is good - but i’m not looking for  
a  
template engine - does it provide hooks to generate html without using  
templates. the code i’m working on attm can do things like this:

```
 [ahoward@localhost xx-0.0.0]$ cat a.rb
 require "xx"
 class Table < ::Array
   include XX::XHTML

   def to_xhtml
     xhtml__{

       html__{
         head __{ title__ { "table demo" } }

         h1__(:style => :sweet){ "this is a table " }

         h__{ "<malformed html & open tags" }

         table__(:width => 42, :height => 42){
           each{|row| tr __{ row.each{|cell| td__ cell } } }
         }
       }

     }.pretty
   end
 end

 puts Table[%w( 0 1 2 ), %w( a b c )].to_xhtml

 [ahoward@localhost xx-0.0.0]$ ruby -I./lib a.rb
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 

```

“[http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd)”\>  
  
  
table demo

# this is a table
\<malformed html & open  
tags  
  
  
  
  
  
  
  
  
  
  

| 0 | 1 | 2 |
| a | b | c |

  

coming soon to a store near you 😉

regards.

-a

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 16, 2005, 6:42am UTC](https://www.ruby-forum.com/t/adding-any-text-to-a-rexml-doc-bump/66769/7 "2005-12-16T06:42:24Z")

</div>

On Fri, 16 Dec 2005, Ezra Z. wrote:

> Ahh thats what the non matching regex was for…

caught in the act… mine worked… but it wasn’t nice looking 😉

-a

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 16, 2005, 6:51am UTC](https://www.ruby-forum.com/t/adding-any-text-to-a-rexml-doc-bump/66769/8 "2005-12-16T06:51:26Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

On 2005.12.16 14:38, removed\_email\_address@domain.invalid wrote:

> > >
> 
> templates. the code i’m working on attm can do things like this:  
> head\_\_{ title\_\_{ “table demo” } }  
> }.pretty  
> table demo  
> c
> 
> coming soon to a store near you 😉

Very nice! (Well, sans underscores:)

Will you make libxml2[1] an alternative backend? It is quite  
a bit faster, which may or may not be important to people.

> regards.
> 
> -a

E

[1] [http://xml-tools.rubyforge.org](http://xml-tools.rubyforge.org)  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDol3YxvA1l6h+MUMRApOaAJwNvEboVkzD+rSI6XPu9wQNWXdRqgCghsH5  
fk5nmlI2wRb2dOhff/o8lR8=  
=uORR  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [December 16, 2005, 7:09am UTC](https://www.ruby-forum.com/t/adding-any-text-to-a-rexml-doc-bump/66769/9 "2005-12-16T07:09:28Z")

</div>

On Fri, 16 Dec 2005, Eero S. wrote:

> > coming soon to a store near you 😉
> 
> Very nice! (Well, sans underscores:)

glad you like the look of it. i struggled with the underscore thing and  
here’s how i got there:

- wanted access to instance data. ergo mixin. ergo can’t be  
clobbering the  
objects methods with a billion others.

- didn’t want a ‘blanket’ method missing. i wanted to a way to say  
that  
only ‘tag’ methods would be handled in method\_missing - not  
everything.  
otherwise

- needed to address methods/tag like ‘p’, ‘a’, ‘i’ - which can easily  
be  
methods and/or local vars

- wanted a way to skim the code and be able to tell which methods  
were  
generating tags and which were not

- wanted a way to bounce on the % key in vi and balance tags… well  
that  
one doesn’t have to do with underscores i guess…

anyhow. i hope people will row to see that being able to **safely**  
mixin  
these kinds of html generation methods, still being able to find syntax  
errors, and being able to quickly tell markup methods from others makes  
it  
o.k. my boss and i struggled with it - but it was the best approach in  
the  
end when considering the above.

> Will you make libxml2[1] an alternative backend?

i’d be happy to look at it… send me a link if it’s not on raa or  
rubyforge…

> It is quite a bit faster, which may or may not be important to people.

it is. this will be used on dynamic websites.

> [1] [http://xml-tools.rubyforge.org](http://xml-tools.rubyforge.org)

oh. didn’t see that at first 😉

cheers.

-a
