[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[REXML] is my installation not working?

Boris Glawe

1/24/2005 11:11:00 PM

Hi,

I am trying to parse an xml file on my fedora Core 3 machine.
I started with a tutorial from this site:
http://www.germane-software.com/software/rexml/docs/tut...

#!/usr/bin/ruby

require "rexml/document"
file = File.new( "mydoc.xml" )
doc = REXML::Document.new file

When executing this trivial peace of code I get the message:

/usr/lib/ruby/1.8/rexml/element.rb:2:in `require': No such file to load --
rexml/namespace (LoadError)
from /usr/lib/ruby/1.8/rexml/element.rb:2
from /usr/lib/ruby/1.8/rexml/document.rb:1:in `require'
from /usr/lib/ruby/1.8/rexml/document.rb:1
from ./test.rb:3:in `require'
from ./test.rb:3

What's the problem? Is something wrong in the code or is my installation missing
this "rexml/namespace" file?

This for any hint.

greets Boris
11 Answers

Zach Dennis

1/24/2005 11:43:00 PM

0

Boris Glawe wrote:
> Hi,
>
> I am trying to parse an xml file on my fedora Core 3 machine.
> I started with a tutorial from this site:
> http://www.germane-software.com/software/rexml/docs/tut...
>
> #!/usr/bin/ruby
>
> require "rexml/document"
> file = File.new( "mydoc.xml" )
> doc = REXML::Document.new file
>
> When executing this trivial peace of code I get the message:
>
> /usr/lib/ruby/1.8/rexml/element.rb:2:in `require': No such file to load
> -- rexml/namespace (LoadError)
> from /usr/lib/ruby/1.8/rexml/element.rb:2
> from /usr/lib/ruby/1.8/rexml/document.rb:1:in `require'
> from /usr/lib/ruby/1.8/rexml/document.rb:1
> from ./test.rb:3:in `require'
> from ./test.rb:3
>
> What's the problem? Is something wrong in the code or is my installation
> missing this "rexml/namespace" file?
>
> This for any hint.

The xml file "mydoc.xml" has to exist, for this tutorial to work. It
doesn't unless you created it, last time I checked. A few more lines
down he gives a xml example of using a String, copy and paste that into
a file and call if "mydoc.xml". Let us know if it don't go... happy rubying,

Zach


Boris Glawe

1/25/2005 12:37:00 AM

0


>
>
> The xml file "mydoc.xml" has to exist, for this tutorial to work. It
> doesn't unless you created it, last time I checked. A few more lines
> down he gives a xml example of using a String, copy and paste that into
> a file and call if "mydoc.xml". Let us know if it don't go... happy
> rubying,
>
> Zach
>
>

The file exists and is a valid xml file according to the firefox DOM expector.

I've scanned my whole disk: there is no file called "namespace.rb" on the whole
system.

The strange thing is, that the required file has been part of the ruby-libs
package before the last upgrade. But after having upgraded to the newest ruby
version, the file was not there any more (The upgrade was provided by fedora).

Would you agree, that the installation/package is broken?

Thanks

Boris

Nicholas Van Weerdenburg

1/25/2005 12:40:00 AM

0

Did you check for the namespace file? I have a namespace.rb in my
rexml directory.

Nick

On Tue, 25 Jan 2005 08:15:50 +0900, Boris Glawe <boris@boris-glawe.de> wrote:
> Hi,
>
> I am trying to parse an xml file on my fedora Core 3 machine.
> I started with a tutorial from this site:
> http://www.germane-software.com/software/rexml/docs/tut...
>
> #!/usr/bin/ruby
>
> require "rexml/document"
> file = File.new( "mydoc.xml" )
> doc = REXML::Document.new file
>
> When executing this trivial peace of code I get the message:
>
> /usr/lib/ruby/1.8/rexml/element.rb:2:in `require': No such file to load --
> rexml/namespace (LoadError)
> from /usr/lib/ruby/1.8/rexml/element.rb:2
> from /usr/lib/ruby/1.8/rexml/document.rb:1:in `require'
> from /usr/lib/ruby/1.8/rexml/document.rb:1
> from ./test.rb:3:in `require'
> from ./test.rb:3
>
> What's the problem? Is something wrong in the code or is my installation missing
> this "rexml/namespace" file?
>
> This for any hint.
>
> greets Boris
>
>


--
Nicholas Van Weerdenburg


Nicholas Van Weerdenburg

1/25/2005 12:50:00 AM

0

Sure sounds like it. Maybe the maintainer disagreed with XML's
namespace implementation :). I've heard that it was a fairly heated
process.


On Tue, 25 Jan 2005 09:40:50 +0900, Boris Glawe <boris@boris-glawe.de> wrote:
>
> >
> >
> > The xml file "mydoc.xml" has to exist, for this tutorial to work. It
> > doesn't unless you created it, last time I checked. A few more lines
> > down he gives a xml example of using a String, copy and paste that into
> > a file and call if "mydoc.xml". Let us know if it don't go... happy
> > rubying,
> >
> > Zach
> >
> >
>
> The file exists and is a valid xml file according to the firefox DOM expector.
>
> I've scanned my whole disk: there is no file called "namespace.rb" on the whole
> system.
>
> The strange thing is, that the required file has been part of the ruby-libs
> package before the last upgrade. But after having upgraded to the newest ruby
> version, the file was not there any more (The upgrade was provided by fedora).
>
> Would you agree, that the installation/package is broken?
>
> Thanks
>
> Boris
>
>


--
Nicholas Van Weerdenburg


William James

1/25/2005 3:21:00 AM

0


Boris Glawe wrote:
> Hi,
>
> I am trying to parse an xml file on my fedora Core 3 machine.
> I started with a tutorial from this site:
> http://www.germane-software.com/software/rexml/docs/tut...


If all you need is minimal xml parsing, try this:

.. class String
.. def get_attr
.. s = self
.. h = Hash.new
.. while s =~ /(\w+)="([^"]*)"/m
.. h[ $1 ] = $2
.. s = $'
.. end
.. h
.. end
.
.. def span( tagname )
.. s = self
.. while (s =~ Regexp.new(
.. '(<'+tagname+'.*?>)(.*?)</'+tagname+'>',
.. Regexp::MULTILINE))
.. yield( $1, $2 )
.. s = $'
.. end
.. end
.. end
.
.. s = ''
.. $<.each_line {|x| s=s+x}
.. s.span('section') { |tag,text|
.. puts "Section: " + tag.get_attr['name']
.. text.span('item') { |tag,text|
.. a = tag.get_attr
.. puts " Item: upc=#{a['upc']} stock=#{a['stock']}"
.. text.span('name') { |tag,name|
.. puts " Name: " + name
.. }
.. text.span('price') { |tag,price|
.. puts " Price: " + price
.. }
.. }
.. }


With this input:

<inventory title="OmniCorp Store #45x10^3">
<section name="health">
<item upc="123456789" stock="12">
<name>Invisibility Cream</name>
<price>14.50</price>
<description>Makes you invisible</description>
</item>
<item upc="445322344" stock="18">
<name>Levitation Salve</name>
<price>23.99</price>
<description>Levitate yourself for up to 3 hours per
application</description>
</item>
</section>
<section name="food">
<item upc="485672034" stock="653">
<name>Blork and Freen Instameal</name>
<price>4.95</price>
<description>A tasty meal in a tablet; just add
water</description>
</item>
<item upc="132957764" stock="44">
<name>Grob winglets</name>
<price>3.56</price>
<description>Tender winglets of Grob. Just add
water</description>
</item>
</section>
</inventory>

the output is


.. Section: health
.. Item: upc=123456789 stock=12
.. Name: Invisibility Cream
.. Price: 14.50
.. Item: upc=445322344 stock=18
.. Name: Levitation Salve
.. Price: 23.99
.. Section: food
.. Item: upc=485672034 stock=653
.. Name: Blork and Freen Instameal
.. Price: 4.95
.. Item: upc=132957764 stock=44
.. Name: Grob winglets
.. Price: 3.56

William James

1/25/2005 3:24:00 AM

0


Boris Glawe wrote:
> Hi,
>
> I am trying to parse an xml file on my fedora Core 3 machine.
> I started with a tutorial from this site:
> http://www.germane-software.com/software/rexml/docs/tut...


If all you need is minimal xml parsing, try this:

.. class String
.. def get_attr
.. s = self
.. h = Hash.new
.. while s =~ /(\w+)="([^"]*)"/m
.. h[ $1 ] = $2
.. s = $'
.. end
.. h
.. end
.
.. def span( tagname )
.. s = self
.. while (s =~ Regexp.new(
.. '(<'+tagname+'.*?>)(.*?)</'+tagname+'>',
.. Regexp::MULTILINE))
.. yield( $1, $2 )
.. s = $'
.. end
.. end
.. end
.
.. s = ''
.. $<.each_line {|x| s=s+x}
.. s.span('section') { |tag,text|
.. puts "Section: " + tag.get_attr['name']
.. text.span('item') { |tag,text|
.. a = tag.get_attr
.. puts " Item: upc=#{a['upc']} stock=#{a['stock']}"
.. text.span('name') { |tag,name|
.. puts " Name: " + name
.. }
.. text.span('price') { |tag,price|
.. puts " Price: " + price
.. }
.. }
.. }


With this input:

<inventory title="OmniCorp Store #45x10^3">
<section name="health">
<item upc="123456789" stock="12">
<name>Invisibility Cream</name>
<price>14.50</price>
<description>Makes you invisible</description>
</item>
<item upc="445322344" stock="18">
<name>Levitation Salve</name>
<price>23.99</price>
<description>Levitate yourself for up to 3 hours per
application</description>
</item>
</section>
<section name="food">
<item upc="485672034" stock="653">
<name>Blork and Freen Instameal</name>
<price>4.95</price>
<description>A tasty meal in a tablet; just add
water</description>
</item>
<item upc="132957764" stock="44">
<name>Grob winglets</name>
<price>3.56</price>
<description>Tender winglets of Grob. Just add
water</description>
</item>
</section>
</inventory>

the output is


.. Section: health
.. Item: upc=123456789 stock=12
.. Name: Invisibility Cream
.. Price: 14.50
.. Item: upc=445322344 stock=18
.. Name: Levitation Salve
.. Price: 23.99
.. Section: food
.. Item: upc=485672034 stock=653
.. Name: Blork and Freen Instameal
.. Price: 4.95
.. Item: upc=132957764 stock=44
.. Name: Grob winglets
.. Price: 3.56

Boris Glawe

1/25/2005 9:58:00 AM

0

Thanks for the replies !

I've reported the bug here (you need an account for fedora's bugzilla):

https://bugzilla.redhat.com/bugzilla/show_bug.cgi...

Work is in progress according to the maintainer.

greets Boris

Jacek

1/25/2005 10:46:00 AM

0

Boris Glawe wrote:

> Thanks for the replies !
>
> I've reported the bug here (you need an account for fedora's bugzilla):
>
> https://bugzilla.redhat.com/bugzilla/show_bug.cgi...
>
> Work is in progress according to the maintainer.
>
> greets Boris
I use Fedora Core 3 and file indeed is missing.
Cheers, Jacek Balcerski

Boris Glawe

1/25/2005 11:15:00 AM

0


>
> I use Fedora Core 3 and file indeed is missing.
> Cheers, Jacek Balcerski
>

The file has been put into the wrong package according to the package maintainer.

Install the ruby-tcltk package and it will work again.

greets Boris

William James

1/25/2005 7:43:00 PM

0

Previous version was too bloated.

.. class String
.. def span( tagname )
.. self.scan( Regexp.new(
.. '(<'+tagname+'.*?>)(.*?)</'+tagname+'>',
.. Regexp::MULTILINE ) ) { |a,b| yield a,b }
.. end
.. def get_attr
.. h = Hash.new
.. self.scan( /(\w+)="([^"]*)"/m ).each { |a,b|
.. h[ a ] = b }
.. h
.. end
.. end
.
.. s = ''
.. $<.each_line {|x| s=s+x}
.
.. s.span('section') { |tag,text|
.. puts "Section: " + tag.get_attr['name']
.. text.span('item') { |tag,text|
.. a = tag.get_attr
.. puts " Item: upc=#{a['upc']} stock=#{a['stock']}"
.. text.span('name') { |tag,name|
.. puts " Name: " + name
.. }
.. text.span('price') { |tag,price|
.. puts " Price: " + price
.. }
.. }
.. }