Skip to content

Instantly share code, notes, and snippets.

Created September 12, 2013 18:02
Show Gist options
  • Save anonymous/6541491 to your computer and use it in GitHub Desktop.
Save anonymous/6541491 to your computer and use it in GitHub Desktop.
require "Nokogiri"
require 'active_support/core_ext/hash/conversions'
puts "type in the full path to the file to be parsed."
file = gets.chomp.to_s
# Grab the file that needs to be parsed
f = File.open(file)
# Parse the XML
doc = Nokogiri::XML(f)
# Create a new hash of the data
doc = Hash.from_xml(doc.to_s)
# Create an array of the waypoint data
waypoints = doc["gpx"]["wpt"]
# Profit!
puts "=-=-=-=-=-=-=-=-="
puts "Fish are here =>"
puts "\n"
waypoints.each do |wpt|
puts "Waypoint: " + wpt["name"]
puts "Coords: " + wpt["lat"] + ", " + wpt["lon"]
end
puts "\n"
puts "=-=-=-=-=-=-=-=-="
new_page = Nokogiri::XML::Builder.new do |xml|
xml.gpx{
xml.version "1.1"
xml.creator "Directional_fish"
waypoints.each do |line|
xml.wpt{
xml.lat line["lat"]
xml.lon line["lon"]
xml.name "test"
xml.sym "dot"
}
end
xml.rte{
xml.name "test"
xml.desc
xml.number
}
}
end
File.open("/Users/hayduke19us/Documents/test.gpx", 'w') do |write|
write.puts new_page.to_xml
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment