pauldix/sax-machine — Issue #27: Retrieving attribute value and content from root element?
Author: juskoljo
Created: 2011-11-08 08:49:42+00:00
State: open

Hi,

I'm using sax-machine v0.1.0 with Ruby 1.8.7 p352 and having problem retrieving root elements attribute and element value.
Should example1 even work? Nokogiri version is 1.5.0.

require 'rubygems'
require 'sax-machine'

module Example1
class RootElement
include SAXMachine
attribute :attr
value :value
end
end

# example xml
xml = 'value_found'

# does not work as expected?
obj = Example1::RootElement.parse(xml)
p obj.attr
# => nil
p obj.value
# => nil

module Example2
class RootElement
include SAXMachine
attribute :attr
value :value
end
class Document
include SAXMachine
element :root, :class => RootElement
end
end

# working ok
obj = Example2::Document.parse(xml)
p obj.root.attr
# => "attr_found"
p obj.root.value
# => "value_found"

Thanks in advance,
Jussi Koljonen