Parsing KML files with REXML?

Hello,

I’m only getting started with Ruby, and need to edit KML files.

According to this article, it looks like two major tools are available to parse XML files: REXML which is pure Ruby and is included in the Windows package, and Nokogiri which is a gem and thus requires an extra stetp for users (which I’d like to avoid if possible).

Can REXML edit KML files, or is Nokogiri required?

Thank you.

Through googling and trial and error… the answer is yes:

require 'rexml/document'
include REXML

xmlfile = File.new("input.kml")
xmldoc = Document.new(xmlfile)

xmldoc.elements.each("kml/Document/Folder"){|mydocument|
  #puts mydocument.elements["name"].text

  mydocument.elements.each("Placemark"){|mystuff|
	  puts mystuff.elements["name"].text
  }
}

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs