# How do i create & insert data into xml file in ruby

**URL:** <https://www.ruby-forum.com/t/how-do-i-create-insert-data-into-xml-file-in-ruby/101358>\
**Category:** Rails\
**Created:** [August 4, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/how-do-i-create-insert-data-into-xml-file-in-ruby/101358 "2006-08-04T14:17:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![narayana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f6c823/32.png) [@narayana](https://www.ruby-forum.com/u/narayana)\
**Post date:** [August 4, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/how-do-i-create-insert-data-into-xml-file-in-ruby/101358/1 "2006-08-04T14:17:11Z")

</div>

hello

How do i create new xml file & insert data into that new xml file in  
ror  
plz explain with example code.(say i have to insert all the values of a  
table into xml file )

advance thx  
Have a pleasant day

narayana

---

<div class="post-metadata">

**Author:** ![narayana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f6c823/32.png) [@narayana](https://www.ruby-forum.com/u/narayana)\
**Post date:** [August 4, 2006, 4:38pm UTC](https://www.ruby-forum.com/t/how-do-i-create-insert-data-into-xml-file-in-ruby/101358/2 "2006-08-04T16:38:27Z")

</div>

Narayana Karthik wrote:

> hello
> 
> How do i create new xml file & insert data into that new xml file in  
> ror  
> plz explain with example code.(say i have to insert all the values of a  
> table into xml file )
> 
> advance thx  
> Have a pleasant day
> 
> narayana

Hi Narayana,

You create an rxml file in one of your views. In that file, you do  
something along these lines:

xml.instruct!  
#=\> \<?xml version="1.0" encoding="UTF-8"?\>  
xml.div( :class=\> “leadNotification”) do  
xml.timestamp(Time.now)  
xml.lead do  
xml.lead\_number( @lead.id )  
xml.first\_name( @lead.first\_name )

```
            ...
    end

```

end

This example is something I used to send an outgoing email in XML  
format. Obviously, your example will be a little different but  
hopefully this is enough to get you going. I’m pretty sure if you  
search google with “XML and RAILS and RXML” then you will find more  
complete examples.

Regards,

Michael
