0

I'm using REXML for ruby serialization.

Is there a way for me to just call a method to dump the object to XML, and then call another method to load the XML data into a Ruby object?

For example, the Ox gem supports save and parse_obj methods to quickly dump and load objects.

MxLDevs
  • 19,048
  • 36
  • 123
  • 194
  • In general we don't use XML for this anymore because it's too verbose. Instead JSON and YAML are preferred for most cases, but if you don't need to support other languages at all, then consider using [Marshall](http://www.ruby-doc.org/core-2.1.3/Marshal.html). Is there some reason you must use XML? – the Tin Man Sep 30 '14 at 20:21
  • The tool I'm using doesn't support loading native libraries for its ruby interpreter, and most of the serialization libraries I've come across rely on them. If there were pure-ruby implementations of JSON or YAML serializers those would work as well. – MxLDevs Sep 30 '14 at 20:28
  • Can you load external gems that don't use native interfaces? There are pure-Ruby YAML and JSON parsers, but they're not part of Ruby itself. – the Tin Man Sep 30 '14 at 20:50
  • I am unable to load gems, but I can copy the script source and load those directly, which is what I've done to load REXML. If you can point me to some of those parsers that would be great. I looked at `pure_json` but it used a `StringScanner` class that was implemented natively. – MxLDevs Sep 30 '14 at 20:57
  • Just do a search for "pure ruby json" and "pure ruby yaml" and nose around in the results. – the Tin Man Sep 30 '14 at 21:15

0 Answers0