The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Converting from REXML to Nokogiri

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eric Hodel

Posts: 660
Nickname: drbrain
Registered: Mar, 2006

Eric Hodel is a long-time Rubyist and co-founder of Seattle.rb.
Converting from REXML to Nokogiri Posted: Jun 17, 2009 7:40 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Eric Hodel.
Original Post: Converting from REXML to Nokogiri
Feed Title: Segment7
Feed URL: http://blog.segment7.net/articles.rss
Feed Description: Posts about and around Ruby, MetaRuby, ruby2c, ZenTest and work at The Robot Co-op.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Eric Hodel
Latest Posts From Segment7

Advertisement

Nokogiri is pretty darn cool, certainly far cooler than REXML. I switched UPnP to Nokogiri, and here’s a handy guide.

require 'rexml/document'

Becomes

require 'nokogiri'
REXML::Document.new

Becomes

Nokogiri::XML

Both accept String or IO objects

my_element.element['element/path']

Becomes

my_element.at 'element > path'

You can use CSS in #at

my_element.each_element 'element/path' do |sub_element|

Becomes

my_element.xpath('./xmlns:element/xmlns:path').each do |sub_element|

”.” is used to select sub-elements of this one

See also Nokogiri’s Node documentation.

Read: Converting from REXML to Nokogiri

Topic: My Apprenticeship - Wednesday, June 16, 2004 Previous Topic   Next Topic Topic: No More Projects

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use