Skip to content

Instantly share code, notes, and snippets.

@toshi3221
Created March 2, 2015 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toshi3221/d92a3691084eb45dd8c3 to your computer and use it in GitHub Desktop.
Save toshi3221/d92a3691084eb45dd8c3 to your computer and use it in GitHub Desktop.
YAML⇔XML相互変換
require 'active_support/core_ext'
require 'yaml'
require "rexml/document"
# YAML→XML
open('ja.xml', 'w') do |f|
f.write YAML.load_file('ja.yml').to_xml
end
# XML→YAML
doc = REXML::Document.new(File.new("ja.xml"))
open('ja2.yml', 'w') do |f|
f.write Hash.from_xml(doc.to_s)['hash'].to_yaml
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment