# RXML: \<ruby:put expr="1+2"/\>

**URL:** <https://www.ruby-forum.com/t/rxml-ruby-put-expr-1-2/110863>\
**Category:** Rails\
**Created:** [July 31, 2007, 4:59pm UTC](https://www.ruby-forum.com/t/rxml-ruby-put-expr-1-2/110863 "2007-07-31T16:59:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Canatella](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Canatella](https://www.ruby-forum.com/u/Canatella)\
**Post date:** [July 31, 2007, 4:59pm UTC](https://www.ruby-forum.com/t/rxml-ruby-put-expr-1-2/110863/1 "2007-07-31T16:59:57Z")

</div>

Hello  
railers,

I’ve always been annoyed by the fact that ERB doesn’t respect XML  
specs.  
As I mostly write XHTML, I’m trying to write a renderer using only  
valid  
XML files. Here is an example of a file so you get the feeling of  
what  
it’s going to  
do:

 \<?xml version="1.0" encoding="utf-8"? \> '1 + 2 = ' + (1 + 2).to\_s 
# title It's still in the early development stage and I would like advice on the implementation and the various ruby/rails XML element that could/ should be implemented. It uses REXML to parse the file. For each node encountered, a method is defined which will be called at render time to render the node. At render time, a copy of the parsed tree is created, using the output of the previously defined methods. For now, I have a put, attr and eval tag. I'm not satisfied with the eval + block implementation and syntax: The syntax doesn't quite feel alright. If anyone has suggestion, they are welcome. Also in the implementation, I cannot evaluate the expressions in a clean binding because of the need to have a reference to the render\_node method. It goes like: Kernel.eval(%Q[#{node['expr']} do | #{node['args]}| render\_node(current\_node, parent\_node, binding) end ]) If somebody is interested and is willing to review my code, I would be very happy to hear their thought/ advice/... The code is available at http://www.cosinux.org/~dam/rxml.tar.gz Best regards, -- Damien MERENNE http://blog.cosinux.org/

---

<div class="post-metadata">

**Author:** ![Canatella](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@Canatella](https://www.ruby-forum.com/u/Canatella)\
**Post date:** [July 31, 2007, 5:05pm UTC](https://www.ruby-forum.com/t/rxml-ruby-put-expr-1-2/110863/2 "2007-07-31T17:05:59Z")

</div>

Sorry for the formating. Google did not accept sending the mail from  
my mutt client. Here is a hopefully better formatted version.

On 31 juil, 16:58, Canatella [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
Hello railers,

I’ve always been annoyed by the fact that ERB doesn’t respect XML  
specs. As I mostly write XHTML, I’m trying to write a renderer using  
only valid XML files. Here is an example of a file so you get the  
feeling of what it’s going to do:

\<?xml version="1.0" encoding="utf-8"?\> '1 + 2 = ' + (1 + 2).to\_s 

# title

It’s still in the early development stage and I would like advice on  
the implementation and the various ruby/rails XML element that could/  
should be implemented.

It uses REXML to parse the file. For each node encountered, a method  
is defined which will be called at render time to render the node. At  
render time, a copy of the parsed tree is created, using the output of  
the previously defined methods.

For now, I have a put, attr and eval tag. I’m not satisfied with the  
eval + block implementation and syntax:

The syntax doesn’t quite feel alright. If anyone has suggestion, they  
are welcome.

Also in the implementation, I cannot evaluate the expressions in a  
clean binding because of the need to have a reference to the  
render\_node method. It goes like:

Kernel.eval(%Q[  
#{node[‘expr’]} do |#{node['args]}|  
render\_node(current\_node, parent\_node, binding)  
end  
])

If somebody is interested and is willing to review my code, I would be  
very happy to hear their thought/advice/…

The code is available athttp://www.cosinux.org/~dam/rxml.tar.gz

Best regards,

–  
Damien MERENNE  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://blog.cosinux.org/](http://blog.cosinux.org/)
