How to get a Node element from Nokogiri :: XML :: Reader?

The docs state that you can iterate over nodes with .each, and node will be returned to the block. However, it is not. The returned "node" is just an instance of Reader.

I need to get the node object so that I can access:

node.content 

However, this seems to be poorly documented. Anyway, I can’t understand how to make something so simple after 2 hours of trying. Any help is appreciated.

+4
source share
1 answer

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! 
+2
source

Source: https://habr.com/ru/post/1343953/


All Articles