REXML::Document.write( my_file, 0, true, false )

I am reading in simple xml document, adding an element and writing it out.

<?xml version="1.0"?>
<!-- my comment -->
<shopping_list_doc>
   <food_group name="Veggies">
     <description>
       the green ones
     </description>
     <item name="broccoli"/>
  </food_group>
</shopping_list_doc>

But when I write out the document I get

<?xml version="1.0"?>
<!-- my comment
-->
<shopping_list_doc>
   <food_group name="Veggies">
     <description>
       the green ones
     </description
    >
     <item name="broccoli"
   /><item name="new veggie"
   >
  </food_group
>
</shopping_list_doc

Is there a way to prevent the extra newline characters on closing brackets?
Or am I better to call an external command to do the formatting for me?

THanks,

~S

I am reading in simple xml document, adding an element and writing it out.

<?xml version="1.0"?>
<!-- my comment -->
<shopping_list_doc>
   <food_group name="Veggies">
     <description>
       the green ones
     </description>
     <item name="broccoli"/>
  </food_group>
</shopping_list_doc>

But when I write out the document I get

<?xml version="1.0"?>
<!-- my comment
-->
<shopping_list_doc>
   <food_group name="Veggies">
     <description>
       the green ones
     </description
    >
     <item name="broccoli"
   /><item name="new veggie"
   >
  </food_group
>
</shopping_list_doc
>

Is there a way to prevent the extra newline characters on closing brackets?

perhaps -
  REXML::Document.write( my_file, 0 )
or even -
  REXML::Document.write( my_file )

cheers,
Mark

···

On 10/25/05, Shea Martin <sheam@ns.sympatico.ca> wrote:

Or am I better to call an external command to do the formatting for me?

THanks,

~S

Mark Hubbart wrote:

···

On 10/25/05, Shea Martin <sheam@ns.sympatico.ca> wrote:

I am reading in simple xml document, adding an element and writing it out

???

Mark Hubbart wrote:

>> I am reading in simple xml document, adding an element and writing it out
???

What does "???" mean? Did your reader truncate the message? Or did I
misunderstand your original question?

My response was:

perhaps -
REXML::Document.write( my_file, 0 )
or even -
REXML::Document.write( my_file )

From the rexml docs:

write( output=$stdout, indent_level=-1, transitive=false, ie_hack=false )
[...]
transitive: If transitive is true and indent is >= 0, then the output
will be pretty-printed in such a way that the added whitespace does
not affect the absolute value of the document — that is, it leaves the
value and number of Text nodes in the document unchanged.

I think it is the "transitive" argument that is causing the unusual
formatting. Regardless, removing the extra arguments makes it print
more prettily.

cheers,
Mark

···

On 10/26/05, Shea Martin <sheam@ns.sympatico.ca> wrote:

> On 10/25/05, Shea Martin <sheam@ns.sympatico.ca> wrote:

Mark Hubbart wrote:
...

From the rexml docs:

write( output=$stdout, indent_level=-1, transitive=false, ie_hack=false )
[...]
transitive: If transitive is true and indent is >= 0, then the output
will be pretty-printed in such a way that the added whitespace does
not affect the absolute value of the document — that is, it leaves the
value and number of Text nodes in the document unchanged.

I think it is the "transitive" argument that is causing the unusual
formatting. Regardless, removing the extra arguments makes it print
more prettily.

But at the expense of adding new white space to your document.

<foo><bar/></foo>

is not the same document as
<foo>
   <bar/>
</foo>

because the latter has white space content (after <foo>, after <bar/>, and before <bar/> ) not found in the first version.

James

···

--

http://www.ruby-doc.org - The Ruby Documentation Site
http://www.rubyxml.com - News, Articles, and Listings for Ruby & XML
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys

Mark Hubbart wrote:

···

On 10/26/05, Shea Martin <sheam@ns.sympatico.ca> wrote:

Mark Hubbart wrote:

On 10/25/05, Shea Martin <sheam@ns.sympatico.ca> wrote:

I am reading in simple xml document, adding an element and writing it out

???

What does "???" mean? Did your reader truncate the message? Or did I
misunderstand your original question?

Yeah, I tried with two readers, and both of them showed an empty responce.
~S