Created
March 2, 2015 08:20
-
-
Save toshi3221/d92a3691084eb45dd8c3 to your computer and use it in GitHub Desktop.
YAML⇔XML相互変換
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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