ruby - Nokogiri and finding element by name -
i parsing xml file using nokogiri following snippet:
doc.xpath('//root').each |root| puts "# root found" root.xpath('//page').each |page| puts "## page found / #{page['id']} / #{page['name']} / #{page['width']} / #{page['height']}" page.children.each |content| ... end end end
how can parse through elements in page element? there 3 different elements: image, text , video. how can make case statement each element?
honestly, pretty close me..
doc.xpath('//root').each |root| puts "# root found" root.xpath('//page').each |page| puts "## page found / #{page['id']} / #{page['name']} / #{page['width']} / #{page['height']}" page.children.each |child| case child.name when 'image' do_image_stuff when 'text' do_text_stuff when 'video' do_video_stuff end end end end
Comments
Post a Comment