# Create and read XML

**URL:** <https://www.ruby-forum.com/t/create-and-read-xml/119206>\
**Category:** Rails\
**Created:** [November 4, 2007, 11:27pm UTC](https://www.ruby-forum.com/t/create-and-read-xml/119206 "2007-11-04T23:27:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e95f7d/32.png) [@zaid](https://www.ruby-forum.com/u/zaid)\
**Post date:** [November 4, 2007, 11:27pm UTC](https://www.ruby-forum.com/t/create-and-read-xml/119206/1 "2007-11-04T23:27:53Z")

</div>

Hello

I am trying to create and read an xml. But I am not able to store them  
on a map.

I think so:  
xml = Builder:: XmlMarkup.new(:target =\> ‘./inf.xml’, :indent =\> 1)  
xml.id (1)

But I do not know how to save it in the path q I want. Neither as open  
and read it.

Thank you

---

<div class="post-metadata">

**Author:** ![zaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e95f7d/32.png) [@zaid](https://www.ruby-forum.com/u/zaid)\
**Post date:** [November 5, 2007, 6:36pm UTC](https://www.ruby-forum.com/t/create-and-read-xml/119206/2 "2007-11-05T18:36:50Z")

</div>

I’m guessing you probably have this solved by now, but just in case…

> ```
> xml = Builder:: XmlMarkup.new(:target => './inf.xml', :indent => 1)
> 
> ```

Here you are setting the target of a Build::XmlMarkup object to the  
string ‘./inf.xml’ I’m guessing that’s not what you really want.  
Although, I would guess that Ruby isn’t complaining about that since  
your target is an object that responds to the \<\< method.

Try something like this:

f = File.new(“./inf.xml”, “w”)  
xml = Builder::XmlMarkup.new(:target =\> f, :indent =\> 1)  
xml.instruct!  
xml.some\_tag  
f.close

On Nov 4, 5:27 pm, Ramón Castro [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
