Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: HappyMapper.model(XML) #14

Open
burtlo opened this issue Sep 24, 2012 · 3 comments
Open

Feature: HappyMapper.model(XML) #14

burtlo opened this issue Sep 24, 2012 · 3 comments
Labels

Comments

@burtlo
Copy link
Collaborator

burtlo commented Sep 24, 2012

HappyMapper model generator

Currently the most tedious part of HappyMapper is attempting to model the XML data as a HappyMapper class. After that it becomes a fairly enjoyable experience. What if we had a method that could generate for you the source code from a specified XML input.

Within code you would write:

model_text = HappyMapper.model(ADDRESS_XML_DATA)
puts model_text

This would output:

class Address
  include HappyMapper
  has_one :street, String
  has_one :postcode, String
  has_one :housenumber, String
  has_one :city, String
  has_one :country, 'Country'
end

class Country
  include HappyMapper

  content :content, String
  attribute :code, String
end

Perhaps this would be most useful as a command-line application:

$ happymapper address.xml > address.rb
@benoist
Copy link

benoist commented Nov 1, 2012

This would be a nice generator to get you started. Perhaps a generator based on XSD input could even make it possible to change the String in to the correct type.

@Confusion
Copy link

A generator that works for specific XSD's is not that hard (I've written one using Nokogiri and xpath expressions, with some inspiration from Wasabi), estimating it would take me less time than writing the classes by hand), but if you want to be able to handle any XSD, I think it becomes a pretty large task.

A parser based on XML examples may be more useful for most people.

@sshaw
Copy link

sshaw commented Jul 5, 2014

Checkout this XML Schema to Ruby generator: https://github.com/sshaw/jaxb2ruby

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants