ruby - rexml/streamlistner - error: uninitialized constant

J

jsp408

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)
 
R

Robert Klemme

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)

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

robret
 
Z

zycte

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)

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top