Project

xsd-reader

0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
A library of Ruby classes for quick and convenient usage of xsd schemas
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 10.1
~> 3.3

Runtime

 Project Readme

XsdReader

XsdReader provides easy and flexible access to XSD information

Build Status Code Climate

Installation

Rubygems:

gem install xsd-reader

Bundler:

gem 'xsd-reader'

Examples

Load xsd

require 'xsd_reader'
reader = XsdReader::XML.new(:xsd_file => 'ddex-ern-v36.xsd')

Get elements and their child elements

node = reader['NewReleaseMessage']
node.elements.map(&:name) # => ['MessageHeader', 'UpdateIndicator', 'IsBackfill', 'CatalogTransfer', 'WorkList', 'CueSheetList', 'ResourceList', 'CollectionList', 'ReleaseList', 'DealList']

Get attributes

reader['NewReleaseMessage']['MessageHeader'].attributes.map(&:name) # => ['LanguageAndScriptCode']

Get type information of attribute

attribute = reader['NewReleaseMessage']['MessageHeader']['@LanguageAndScriptCode']
attribute.type 				# => 'xs:string'
attribute.type_name			# => 'string'
attribute.type_namespace	# => 'xs'

Get element amount details

node = @reader['NewReleaseMessage']['ResourceList']['SoundRecording']
node.min_occurs			# => 0
node.max_occurs			# => :unbouded
node.multiple_allowed? # true
node.required?			# false
node = @reader['NewReleaseMessage']['MessageHeader']
node.min_occurs			# => nil
node.max_occurs			# => nil
node.multiple_allowed? # false
node.required?			# true