[REXML] is my installation not working?

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/tutorial.html

#!/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

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/tutorial.html

#!/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

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/tutorial.html

#!/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

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/tutorial.html

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 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/tutorial.html

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

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?id=146055

Work is in progress according to the maintainer.

greets Boris

The problem seems to be fixed with the latest fedora update

greets Boris

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

Boris Glawe wrote:

Thanks for the replies !

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

Bug Access Denied

Work is in progress according to the maintainer.

greets Boris

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

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
.. }
.. }
.. }

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

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