# Writing xml

**URL:** <https://www.ruby-forum.com/t/writing-xml/77641>\
**Category:** Rails\
**Created:** [November 29, 2006, 12:48pm UTC](https://www.ruby-forum.com/t/writing-xml/77641 "2006-11-29T12:48:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pabloz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c37758/32.png) [@pabloz](https://www.ruby-forum.com/u/pabloz)\
**Post date:** [November 29, 2006, 12:48pm UTC](https://www.ruby-forum.com/t/writing-xml/77641/1 "2006-11-29T12:48:46Z")

</div>

Hi

I am having a problem with writing xml file. I am using REXML.  
Everything goes fine on IRB, i can add new elements to my existing file,  
add atributes or text. When i print my xml in IRB it looks ok. Then i  
try xml.write(STDOUT, 0), and i get no errors but the xml does not  
change. My persmissions look ok. I am working on windows XP. Any clue?

---

<div class="post-metadata">

**Author:** ![pabloz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c37758/32.png) [@pabloz](https://www.ruby-forum.com/u/pabloz)\
**Post date:** [November 29, 2006, 4:54pm UTC](https://www.ruby-forum.com/t/writing-xml/77641/2 "2006-11-29T16:54:16Z")

</div>

Phlip wrote:

> Stop using IRB and start using unit tests. You should write a little bit  
> of  
> a test case and ‘p’ a result, then run ‘rake recent’ and read your  
> console.  
> If the result is correct, write an assertion that locks it in and  
> repeat.  
> Small experiments with test cases will replace small experiments with  
> IRB,  
> and will preserve a history of correct results. This is how RoR itself  
> was  
> created, and it’s a major reason RoR is so powerful.

thanks for the information! i really need to start using tests then, but  
first i will read a little about them.

---

<div class="post-metadata">

**Author:** ![pabloz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c37758/32.png) [@pabloz](https://www.ruby-forum.com/u/pabloz)\
**Post date:** [November 29, 2006, 4:07pm UTC](https://www.ruby-forum.com/t/writing-xml/77641/3 "2006-11-29T16:07:30Z")

</div>

Pabloz wrote:

> I am having a problem with writing xml file. I am using REXML.  
> Everything goes fine on IRB,

Stop using IRB and start using unit tests. You should write a little bit  
of  
a test case and ‘p’ a result, then run ‘rake recent’ and read your  
console.  
If the result is correct, write an assertion that locks it in and  
repeat.  
Small experiments with test cases will replace small experiments with  
IRB,  
and will preserve a history of correct results. This is how RoR itself  
was  
created, and it’s a major reason RoR is so powerful.

> i can add new elements to my existing file,  
> add atributes or text. When i print my xml in IRB it looks ok. Then i  
> try xml.write(STDOUT, 0), and i get no errors but the xml does not  
> change. My persmissions look ok. I am working on windows XP. Any clue?

STDOUT is your console’s handle as a file stream. It’s not a real file.  
Try  
this:

File.open(‘foo.xml’, ‘w’) {|f| xml.write(f, 0) }

–  
Phlip  
[Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!

---

<div class="post-metadata">

**Author:** ![pabloz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c37758/32.png) [@pabloz](https://www.ruby-forum.com/u/pabloz)\
**Post date:** [November 29, 2006, 5:29pm UTC](https://www.ruby-forum.com/t/writing-xml/77641/4 "2006-11-29T17:29:50Z")

</div>

Hi –

On Wed, 29 Nov 2006, Phlip wrote:

> Pabloz wrote:
> 
> > I am having a problem with writing xml file. I am using REXML.  
> > Everything goes fine on IRB,
> 
> Stop using IRB and start using unit tests.

Well… the world is a big place, and there’s room for lots of things  
🙂 I agree with James Duncan Davidson that the Rails application  
console is a great debugging tool, and I’d say the same about irb in  
general. So are unit tests, of course 🙂

David

–  
David A. Black | removed\_email\_address@domain.invalid  
Author of “Ruby for Rails” [1] | Ruby/Rails training & consultancy [3]  
DABlog (DAB’s Weblog) [2] | Co-director, Ruby Central, Inc. [4]  
[1] [Ruby for Rails](http://www.manning.com/black) | [3] [http://www.rubypowerandlight.com](http://www.rubypowerandlight.com)  
[2] [http://dablog.rubypal.com](http://dablog.rubypal.com) | [4] [http://www.rubycentral.org](http://www.rubycentral.org)

---

<div class="post-metadata">

**Author:** ![pabloz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/c37758/32.png) [@pabloz](https://www.ruby-forum.com/u/pabloz)\
**Post date:** [November 30, 2006, 10:45am UTC](https://www.ruby-forum.com/t/writing-xml/77641/5 "2006-11-30T10:45:15Z")

</div>

On 29 Nov 2006, at 15:54, Pabloz wrote:

> thanks for the information! i really need to start using tests  
> then, but  
> first i will read a little about them.

You may like to watch the latest Peepcode screencast on test-first  
development called, well, Test-First Development:

[http://peepcode.com/articles/2006/11/26/test-first-development](http://peepcode.com/articles/2006/11/26/test-first-development)

Regards,  
Andy S.
