Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ruby - rexml/streamlistner - error: uninitialized constant

12 views
Skip to first unread message

jsp...@comcast.net

unread,
Jun 14, 2006, 10:14:49 PM6/14/06
to
Using ruby 1.8.4-17_rc2, example from Enterprise Integration with ruby
page 109:
#Generates the followwing error: uninitialized constant

Would someone look at this example and annotate what is wrong,

Thank you, John
====================test-xml2.rb==============================
require 'rexml/streamlistener'

class ParcelHistoryListener
include StreamListener

def tag_name
puts tag_name
end

end

Document.parse_stream(
File.new('parcel.xml'),
ParcelHistoryListener.new
)


================= parcel.xml =============================
<?xml version="1.0" encoding="UTF-8"?>
<book name="Directory">
<person surname="Musterman" name="Max">
<address?
<street>2323 Any Street</street>
<postal-code>12345</postal-code>
<city>AnyWhere</city>
</address>
<position longitude="12.15" latitude="56.123"/>
</person>
<person surname="Musterman" name="John">
<address>
<street>2323 Any Street</street>
<postal-code>12345</postal-code>
<city>AnyWhere</city></address>
<position longitude="12.15" latitude="56.123"/>
</person>
</book>


#Generates the followwing error:
# C:/0Ruby/0/XML/xml-stream.rb:5: uninitialized constant
ParcelHistoryListener::StreamListener (NameError)

Robert Klemme

unread,
Jun 15, 2006, 6:17:27 AM6/15/06
to

There is no StreamListener in scope ParcelHistoryListener. You want
REXML::StreamListener.

robret

zycte

unread,
Jun 15, 2006, 7:30:47 AM6/15/06
to

I don't see what you are trying to do with

> def tag_name
> puts tag_name
> end

Basically, this is an infinite recursive procedure. The tag_name after
puts will be resolved by calling the method tag_name again. I think you
want something like:

def start_tag(tag_name, attrs)
puts tag_name
end

0 new messages