Just a simple code example to understand!
1Require'Nokogiri'2 3xml_data=<<XML4<library>5<name><! [Cdata[favorite books]]></name>6<book isbn="11342343">7<title>to Kill A mockingbird</title>8<description><! [Cdata[description#1]] ></description>9<author>harper lee</author>Ten</book> One<book isbn="989894781234"> A<title>catcherinchThe rye</title> -<description><! [Cdata[this isAn extremely intense description.] ></description> -<author>j. D. salinger</author> the</book> -<book isbn="123456789"> -<title>murphy\'s gambit</title> -<description><! [Cdata[daughter finds her dad!]] ></description> +<author>syne mitchell</author> -</book> +</library> A XML at - #Loading Data -Doc =nokogiri::xml (xml_data) - - #use CSS to get to a node, traverse read into book object -DOC.CSS (' Book'). Each do |node| inChildren =Node.children - to Book.create ( +: ISBN = node['ISBN'], -: title = Children.css ('title'). Inner_text, the:d escription = Children.css ('Description'). Inner_text, *: Author = children.css ('author'). Inner_text $ )Panax NotoginsengEnd
Nokogiri How to use