# Does REXML add spaces to comments?

**URL:** <https://rubytalk.org/t/does-rexml-add-spaces-to-comments/15080>\
**Category:** ruby-talk\
**Created:** [1 December 2004 18:32 UTC](https://rubytalk.org/t/does-rexml-add-spaces-to-comments/15080 "2004-12-01T18:32:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phlip1](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@Phlip1](https://rubytalk.org/u/Phlip1)\
**Post date:** [1 December 2004 18:32 UTC](https://rubytalk.org/t/does-rexml-add-spaces-to-comments/15080/1 "2004-12-01T18:32:44Z")

</div>

Rubistas:

I'm using REXML to read and write XML too often.

Whenever REXML saves a comment, it adds linefeeds to it. Because I  
write too often, these are stacking up. Is this my fault? I tried  
various doc.write(f, x) options for the indentation levels.

Ruby 1.8.2 (from the Pragmatic Programmers' way cool installer).

> **···**
>
> --  
> &nbsp;&nbsp;Phlip

---

<div class="post-metadata">

**Author:** ![James\_Britt6](https://avatars.discourse-cdn.com/v4/letter/j/a87d85/32.png) [@James\_Britt6](https://rubytalk.org/u/James_Britt6)\
**Post date:** [2 December 2004 02:18 UTC](https://rubytalk.org/t/does-rexml-add-spaces-to-comments/15080/2 "2004-12-02T02:18:11Z")

</div>

phlip2005@gmail.com wrote:

> Rubistas:
> 
> I'm using REXML to read and write XML too often.
> 
> Whenever REXML saves a comment, it adds linefeeds to it. Because I  
> write too often, these are stacking up. Is this my fault? I tried  
> various doc.write(f, x) options for the indentation levels.

Doesn't seem that way for me:

> **···**
>
> #--------  
> require 'rexml/document'  
> doc = REXML::Document.new( "\<foo\>Text\</foo\>" )  
> doc.root \<\< REXML::Comment.new( 'My Comment')  
> puts doc # \<foo\>Text\<!--My Comment--\>\</foo\>  
> #--------
> 
> This is using
> 
> ruby 1.8.2 (2004-11-06) [i386-mswin32]
> 
> on Win2K
> 
> > Ruby 1.8.2 (from the Pragmatic Programmers' way cool installer).
> 
> I believe this is Curt Hibbs' work, now referred to as the "One-click Installer."
> 
> James

---

<div class="post-metadata">

**Author:** ![Stefan\_Lang](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Stefan\_Lang](https://rubytalk.org/u/Stefan_Lang)\
**Post date:** [2 December 2004 07:58 UTC](https://rubytalk.org/t/does-rexml-add-spaces-to-comments/15080/3 "2004-12-02T07:58:33Z")

</div>

I have the same problem: Read document and write it  
out again with (usually) doc.write(file, 0).  
This adds some (at least one) linefeeds to previously existing ones.

Ruby version: ruby 1.8.2 (2004-11-06) [i686-linux]

> **···**
>
> Am Mittwoch, 1. Dezember 2004 19:32 schrieb phlip2005@gmail.com:
> 
> > Rubistas:
> > 
> > I'm using REXML to read and write XML too often.
> > 
> > Whenever REXML saves a comment, it adds linefeeds to it. Because I  
> > write too often, these are stacking up. Is this my fault? I tried  
> > various doc.write(f, x) options for the indentation levels.
> > 
> > Ruby 1.8.2 (from the Pragmatic Programmers' way cool installer).
> 
> --  
> Stefan

---

<div class="post-metadata">

**Author:** ![Phlip4](https://avatars.discourse-cdn.com/v4/letter/p/90ced4/32.png) [@Phlip4](https://rubytalk.org/u/Phlip4)\
**Post date:** [2 December 2004 02:57 UTC](https://rubytalk.org/t/does-rexml-add-spaces-to-comments/15080/4 "2004-12-02T02:57:44Z")

</div>

James Britt wrote:

> \> Whenever REXML saves a comment, it adds linefeeds to it. Because I  
> \> write too often, these are stacking up. Is this my fault? I tried  
> \> various doc.write(f, x) options for the indentation levels.

> #--------  
> require 'rexml/document'  
> doc = REXML::Document.new( "\<foo\>Text\</foo\>" )  
> doc.root \<\< REXML::Comment.new( 'My Comment')  
> puts doc # \<foo\>Text\<!--My Comment--\>\</foo\>  
> #--------

I cannot reproduce the problem using a 4 line program like that, with a copy  
of the production XML that causes the problem. Thanks for trying. I have to  
look closer at the production then...

> **···**
>
> --  
> &nbsp;&nbsp;Phlip  
> &nbsp;&nbsp;[http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces](http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces)
