[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Indenting REXML output...

Sonny Chee

11/13/2007 5:03:00 AM

Hey Guys,

Anyone know how to get REXML to generate indented XML? At the moment I
get something like this:

<bibliography id='46'><biblioentry>Superglue is great
stuff.</biblioentry></bibliography>

When I really want this:

<bibliography id='46'>
<biblioentry>Superglue is great stuff.</biblioentry>
</bibliography>

Sonny.
--
Posted via http://www.ruby-....

5 Answers

Sonny Chee

11/13/2007 5:34:00 AM

0

Konrad Meyer wrote:
> Quoth Sonny Chee:
>> <bibliography id='46'>
>> <biblioentry>Superglue is great stuff.</biblioentry>
>> </bibliography>
>>
>> Sonny.
>
> You can use a generic XML beautifier on the output. Google is your
> friend.
>
> Regards,

Thanks for the tip, Konrad!

Sonny.
--
Posted via http://www.ruby-....

Robert Klemme

11/13/2007 8:14:00 AM

0

2007/11/13, Sonny Chee <sonny.chee@gmail.com>:
> Konrad Meyer wrote:
> > Quoth Sonny Chee:
> >> <bibliography id='46'>
> >> <biblioentry>Superglue is great stuff.</biblioentry>
> >> </bibliography>
> >>
> >> Sonny.
> >
> > You can use a generic XML beautifier on the output. Google is your
> > friend.

Not necessary. Documentation is your friend.

http://www.germane-software.com/software/rexml/docs/tutorial.html...

robert

--
use.inject do |as, often| as.you_can - without end

Sonny Chee

11/13/2007 3:49:00 PM

0

Robert Klemme wrote:
> 2007/11/13, Sonny Chee <sonny.chee@gmail.com>:
>> Konrad Meyer wrote:
>> > Quoth Sonny Chee:
>> >> <bibliography id='46'>
>> >> <biblioentry>Superglue is great stuff.</biblioentry>
>> >> </bibliography>
>> >>
>> >> Sonny.
>> >
>> > You can use a generic XML beautifier on the output. Google is your
>> > friend.
>
> Not necessary. Documentation is your friend.
>
> http://www.germane-software.com/software/rexml/docs/tutorial.html...
>
> robert

Awesome, even better! Thanks Robert. I was actually reading that
documentation but somehow overlooked that section. Thanks again!

Sonny.

--
Posted via http://www.ruby-....

Jari Williamsson

11/13/2007 4:28:00 PM

0

Sonny Chee wrote:
> Robert Klemme wrote:
>> Not necessary. Documentation is your friend.
>>
>> http://www.germane-software.com/software/rexml/docs/tutorial.html...
>>
>> robert
>
> Awesome, even better! Thanks Robert. I was actually reading that
> documentation but somehow overlooked that section. Thanks again!

Do you get that formatting to work? I get a NameError exception
("undefined local variable or method `transitive'") when I use a second
parameter to doc.write. As in:

require "rexml/document"
doc = REXML::Document.new '<!DOCTYPE foo><myroot />'
doc.root.add_element("other")
doc.write( $stdout, 0 )


Best regards,

Jari Williamsson

Sonny Chee

11/13/2007 5:24:00 PM

0

Jari Williamsson wrote:
> Sonny Chee wrote:
>> Robert Klemme wrote:
>>> Not necessary. Documentation is your friend.
>>>
>>> http://www.germane-software.com/software/rexml/docs/tutorial.html...
>>>
>>> robert
>>
>> Awesome, even better! Thanks Robert. I was actually reading that
>> documentation but somehow overlooked that section. Thanks again!
>
> Do you get that formatting to work? I get a NameError exception
> ("undefined local variable or method `transitive'") when I use a second
> parameter to doc.write. As in:
>
> require "rexml/document"
> doc = REXML::Document.new '<!DOCTYPE foo><myroot />'
> doc.root.add_element("other")
> doc.write( $stdout, 0 )
>
>
> Best regards,
>
> Jari Williamsson

I got the same error message as you did Jari. But I did find the REXML
changelog, which shows the revised method to get pretty printing. This
worked for me.

(http://www.germane-software.com/software/rexml/re...)
======
r1281@bean: ser | 2007-07-24 11:08:48 -0400
Addresses ticket:85

This is a major rewrite of the XML formatting code. The XML writers have
all
been extracted out of the classes and put into their own class
containers.
This makes writing parsers easier, and cleaner.

There are three formatters, which correspond to the previous three XML
writing
modes:

REXML::Formatters::Default
Prints the XML document exactly as it was parsed
REXML::Formatters::Pretty
Pretty prints the XML document, destroying whitespace in the document
REXML::Formatters::Transitive
Pretty prints the XML document, preserving whitespace

All of the write() functions have been deprecated (some are still used,
but
these will also go away) except the write() function on Document, which
is left
for convenience. To pretty print an XML document the canonical way:

formatter = REXML::Formatters::Pretty.new( 5 ) # indent by 5 spaces
formatter.write( document, output
==================================================================

Sonny.

--
Posted via http://www.ruby-....