How do I get a Node element from a Nokogiri::XML::Reader?
The docs state that you can loop through the nodes with .each, and a node will be returned to the block. However, this is not true. The "node" that is returned is just an instance of Reader.
I need to get the Node object so that I can access the:
node.content
However, this appears to be poorly documented. At any rate, I can't开发者_JAVA百科 find out how to do something so simple after 2 hours of trying. Any help is appreciated.
Are you looking for something like this?
require 'nokogiri'
xml = <<eoxml
<x xmlns:tenderlove='http://tenderlovemaking.com/'>
<tenderlove:foo awesome='true'>snuggles!</tenderlove:foo>
<truth>echo chamber</truth>
</x>
eoxml
doc = Nokogiri::XML::Reader(xml)
doc.each do |node|
if node.attributes == {"awesome"=>"true"}
puts node.inner_xml
end
end
# => snuggles!
精彩评论