XML attribute not copied.
jrz opened this issue · 2 comments
jrz commented
When saxing using xml, the attributes of the current root element is not accessible, even though it prints using element.to_s:
parser.for_tag(:product).each do |offer|
puts offer.attributes('id').value
end
Doesn't work. but:
parser.for_tag(:product).each do |offer|
offer = Nokogiri::XML(offer.to_s).elements[0]
puts offer.attributes('id').value
end
does.
xml:
<products>
<product id="1"><name>test1</name><.product>
<product id="2"><name>test2</name><.product>
<product id="3"><name>test3</name><.product>
<products>
soulcutter commented
Very strange! I'll take a look at what is going on with this.
soulcutter commented
I took a look at this, and I think you're perhaps expecting to receive a Nokogiri::XML::Element
but what actually comes back is a Nokogiri::XML::Document
. You can access the attributes via:
parser.for_tag(:product).each do |offer|
puts offer.elements.first.attributes['id'].value
end