XsdReader provides easy and flexible access to XSD information
Rubygems:
gem install xsd-reader
Bundler:
gem 'xsd-reader'
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