tags:

views:

27

answers:

1

Hi i have a XSD that i want to parse. Note that i don't want validate it against a XML but get all enumerations that i have there. For example

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
 <xsd:simpleType name="fruitNames">
  <xsd:restriction base="xsd:string">
  <xsd:enumeration value="banana" />
  <xsd:enumeration value="apple" />
  <xsd:enumeration value="orange" />
  <xsd:enumeration value="mango" />
 </xsd:restriction>
</xsd:simpleType>
</xsd:schema>

I want to extract the enumeration values.. any idea? I tried to play with XSD::Schema but without success..

+2  A: 

XSD is just a flavour of XML so you can use REXML e.g.

require 'rexml/document'
doc = REXML::Document.new(File.new('yourfile.xsd'))
values = doc.elements.to_a('//xsd:enumeration').map { |el| el.attributes['value'] }
=> ["banana", "apple", "orange", "mango"]
mikej
yup, i figured out some hours ago :-)
VP