[Uw-ruby] REXML Prettify

Brian Riggs brian at bordee.com
Sat Dec 1 14:02:07 PST 2007


Steve, Have you tried specifying it from the root, like:   require '/ 
dir_path/ruby_soup.rb'  ? Not sure if that will work, but it would be  
my next move(in trial and error.) -- Brian

On Dec 1, 2007, at 1:39 PM, Steve Dame wrote:

> Thanks in advance from all you Ruby aficionados...
>
> I have my head all twisted around trying to get XML code to pretty  
> print this morning.  Is there any other way to pretty print XML than  
> from rubyful_soup?
>
> Is anyone having trouble with methods for dumping out prettified XML  
> using rubyful_soup?
>
> Out of the Ruby Cookbook I tried using some rubyful_soup example to  
> explore how to pretty print XML
>
> Here's my little test code snippet...
> #!/usr/bin/ruby -w
>
> require 'rubygems'
> require 'rubyful_soup'
>
> orders_xml = %{<orders><order><number>105</number><date>02/10/2006</ 
> date><customer>Corner Store</customer><items><item upc="404100"  
> desc="Red Roses" qty="240" /><item upc="412002" desc="Candy Hearts"  
> qty="160" /></items></order></orders>}
> 	
> soup = BeautifulSoup.new(orders_xml)
> puts soup.prettify
>
>
>
> This outputs the following ONLY if I run it from irb, but not if  
> executed from the script txml.rb
>
> FROM IRB:
>
> irb(main):001:0> require 'rubygems'
> => true
> irb(main):002:0> require 'rubyful_soup'
> => true
>
> irb(main):016:0> orders_xml = %{<orders><order><number>105</ 
> number><date>02/10/2006</date><customer>Corner Store</ 
> customer><items><item upc="404100" desc="Red Roses" qty="240" / 
> ><item upc="412002" desc="Candy Hearts" qty="160" /></items></ 
> order></orders>}
> => "<orders><order><number>105</number><date>02/10/2006</ 
> date><customer>Corner Store</customer><items><item upc=\"404100\"  
> desc=\"Red Roses\" qty=\"240\" /><item upc=\"412002\" desc=\"Candy  
> Hearts\" qty=\"160\" /></items></order></orders>"
>
> irb(main):018:0> soup = BeautifulSoup.new(orders_xml)
> => <orders><order><number>105</number><date>02/10/2006</ 
> date><customer>Corner Store</customer><items><item qty="240"  
> desc="Red Roses" item="" upc="404100"></item><item qty="160"  
> desc="Candy Hearts" item="" upc="412002"></item></items></order></ 
> orders>
>
> irb(main):019:0> puts soup.prettify
>
>   <orders>
>    <order>
>     <number>105
>     </number>
>     <date>02/10/2006
>     </date>
>     <customer>Corner Store
>     </customer>
>     <items>
>      <item qty="240" desc="Red Roses" item="" upc="404100">
>      </item>
>      <item qty="160" desc="Candy Hearts" item="" upc="412002">
>      </item>
>     </items>
>    </order>
>   </orders>
> => nil
>
>
>
> FROM the txml.rb script run from the command line:
>
> % ./txml.rb
> /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in  
> `gem_original_require': No such file to load -- rubyful_soup  
> (LoadError)
>         from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb: 
> 27:in `require'
>         from ./txml.rb:4
>
>
> Any ideas?????   Is this another bogus and buggy contributor to the  
> Ruby body of code?  I installed the
> rubyful_soup
>  with supposedly all of the dependencies required using gem install,  
> so I don't think that is the problem.
>
> -- 
> Stephen Dame
>
> _______________________________________________
> Uw-ruby mailing list
> Uw-ruby at zenspider.com
> http://www.zenspider.com/mailman/listinfo/uw-ruby

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.zenspider.com/pipermail/uw-ruby/attachments/20071201/6b0960cf/attachment.html


More information about the Uw-ruby mailing list