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

S

Shea Martin

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
 
J

James Britt

Mark Hubbart wrote:
...
From the rexml docs:
=20
write( output=3D$stdout, indent_level=3D-1, transitive=3Dfalse, ie_hack= =3Dfalse )
[...]
transitive: If transitive is true and indent is >=3D 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 =97 that is, it leaves th= e
value and number of Text nodes in the document unchanged.
=20
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/>,=20
and before <bar/> ) not found in the first version.



James

--=20

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
 
S

Shea Martin

Mark said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,979
Members
47,579
Latest member
CharaS3188

Latest Threads

Top