Skip to content

Instantly share code, notes, and snippets.

@chumpy
Created January 29, 2012 00:14
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 chumpy/1696377 to your computer and use it in GitHub Desktop.
Save chumpy/1696377 to your computer and use it in GitHub Desktop.
yaml to xml conversion
#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