Hello group,
I’m new to using REXML to parse documents, but quickly getting the hang
of it. Something, however, is giving me a little trouble, so I could
use some help. I’m trying to create a new object, specifically a Movie
from elements in Delicious Library’s XML data file (a Mac program,
found at http://www.delicious-monster.com). Basically, the XML file
stores the good stuff in tag attributes, and I’d rather make a new
objects from the attributes. I can pull the attributes, and puts proves
I’m pulling right, but when I try to push my new objects into an array,
the class identifies itself as an REXML::Element instead of a Movie.
This is the method that puts the new Movies into the array.
def get_movies
temp = @library.root
temp.elements.each(‘items/movie’) { |movie|
@movies.push(Movie.new(movie.attributes[‘uuid’],
movie.attributes[‘fullTitle’], movie.attributes[‘asin’],
movie.attributes[‘mpaarating’], movie.attributes[‘minutes’],
movie.attributes[‘published’], movie.attributes[‘price’]))
puts movie.attributes[‘fullTitle’]
}
end
But, irb tells me this:
irb(main):025:0> movies.class
=> Array
irb(main):026:0> movies[1].class
=> REXML::Element
Am I doing something completely wrong? Shouldn’t the values of the
attributes be passed directly to the constructor and I get a new object
of class Movie?
Thanks for the help,
Eddie