Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: Sven Koesling
examples not working ? [ reply ]  
2010-03-28 09:59
Hello,

after the third day of trying to get libxml-ruby to work I'm a little bit frustrated. I don't even get the examples to run so I think I'm missing something important. Maybe one of You can help?

As I am expecting big XML-responses I chose XML::reader for my first steps. So I tried the code from http://libxml.rubyforge.org:

#! /usr/bin/ruby
# Testskript

require 'rubygems'
require "xml/libxml"

parser = XML::Reader.string("<foo><bar>1</bar><bar>2</bar><bar>3</bar></foo>")
reader.read
assert_equal('foo', reader.name)
assert_equal(nil, reader.value)

3.times do |i|
reader.read
assert_equal(XML::Reader::TYPE_ELEMENT, reader.node_type)
assert_equal('bar', reader.name)
reader.read
assert_equal(XML::Reader::TYPE_TEXT, reader.node_type)
assert_equal((i + 1).to_s, reader.value)
reader.read
assert_equal(XML::Reader::TYPE_END_ELEMENT, reader.node_type)
end

Sure enough I get the error message: "undefined local variable or method `reader'" so I tried to change
parser = XML::Reader...
to reader = XML::Reader...

"undefined method `assert_equal" is the next error message.

As I could not find a working tutorial on the net I wanted to know I someone could please explane this example to me?

Many thanks in advance,
sven