Generate Ruby Classes from Xsd

Generating an object model in Ruby from an XML DTD

You can use the ruby version of xml-simple.

You shouldn't need to install the gem as I believe it's already installed with rails.
http://xml-simple.rubyforge.org/

Generate ruby classes from json document

There is a wonderful gem for doing this. https://github.com/apotonick/representable/

Here's what your representable would look like

module MenuRepresenter
include Representable::JSON

property :id
property :value
property :popup
end

Create your model

class Menu
attr_accessor :id, :value, :popup
end

menu = Menu.new.extend(MenuRepresenter).from_json(json)

# You can convert it back into json via .to_json
# expect(menu.to_json).to eq(json)

The example above shows only the basic implementation, you would want to create another class for the menu item, take a look at the documentation at the github repo for more detailed information.

Is there XML binding library for Ruby (like JAXB)?

Savon should cover SOAP part of it.

XML Schema (XSD) to Rails ActiveRecord Mapping?

Did you try gem magic_model_generator to generate the model from the db?

See:
http://magicmodels.rubyforge.org/magic_model_generator/

Also, how did you load the XSD into your RDBMS? There seems to be plenty of discussion here:
How can I create database tables from XSD files?
Convert XSD into SQL relational tables

Update:
I used Xml Spy (30 free trail, on windows, ug) to build tables from the xsd in a mysql db, then ran magic_model_generator on it to create ActiveRecord classes. It appears to have worked as you would expect, generating validators on the fields based on the the db schema.

XSD Schema Validation in Ruby

As schemas are XML documents themselves you can validate them like any other document. Both an XSD and a DTD for XML Schema can be found on this site http://www.w3.org/2001/XMLSchema.



Related Topics



Leave a reply



Submit