0.02
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A Ruby gem to build XML data from XSD schemas
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
~> 10.1
~> 3.3

Runtime

 Project Readme

xsd-populator

A Ruby gem to produce XML data from XSD schemas and DataProvider objects.

See the data-provider gem: https://github.com/markkorput/data-provider

Build Status

Installation

Rubygems:

gem install xsd-populator

Bundler:

gem 'xsd-populator'

Examples

Load xsd

require 'xsd_populator'
reader = XsdPopulator.new(:xsd => 'ddex-ern-v36.xsd')
reader.populated_xml # => XML-string

Not that in this minimal implementation, no custom data provider is given to the populator, causing it to use the default internal 'XsdExplanationProvider', which produces explanatory XML.

For this elaborate example XSD, this would produce this xml

Using actual custom data providers

In practice, you'd implement a custom DataProvider class (see the data-provider gem) and pass it into the XsdPopulator.

require 'xsd_populator'

data_provider = CustomDataProvider.new(:some => 'data')
reader = XsdPopulator.new(:xsd => 'ddex-ern-v36.xsd', :provider => data_provider)
reader.populated_xml # => XML-string

Producing specific parts of an XML structure

In case you want to produce only a specific part of an XML hierarchy, you can specify an element when initializing the populator object:

reader = XsdPopulator.new(:xsd => 'ddex-ern-v36.xsd', :element => ['NewReleaseMessage', 'MessageHeader'])
reader.populated_xml # => XML-string containing only the part

The :element option takes an array-value representing an element's XPath (in this case that XPath is /NewReleaseMessage/MessageHeader). The specified element become(s) the root-element(s) in the produced XML.

This example would produce this XML