Created
January 29, 2012 00:14
-
-
Save chumpy/1696377 to your computer and use it in GitHub Desktop.
yaml to xml conversion
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' | |
class YamlToXml | |
def self.yaml_to_xml file_to_read, file_to_write | |
doc = String.new | |
File.open( file_to_read ) { |yf| doc << YAML.parse( yf ).transform.to_xml } | |
File.open( file_to_write, 'w' ) { |f| f.write( doc ) } | |
end | |
def self.xml_to_yaml file_to_read, file_to_write | |
doc = Hash.new | |
File.open( file_to_read ) { |xf| doc = Hash.from_xml( xf ) } | |
File.open( file_to_write, 'w' ) { |f| f.write( doc.to_yaml ) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment