Skip to content

invadersmustdie/xpain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Abstract
========

DSL for creating simple xsd files (not xsd-feature complete)

Yeah for sure I could just learn writing xsd without copy'n'paste, but why not learning it by implementing a dsl for
creating it :)

Example
=======

schema = XPain::Builder.new do |xsd|
  xsd.schema do

    xsd.define_complex_type "mystring" do
      xsd.extension :base => "string" do
        xsd.attribute :name => "type", :type => "string", :use => "optional"
      end
    end

    xsd.define_complex_type "myint", :type => "all" do
      xsd.extension :base => "integer" do
        xsd.attribute :name => "type", :type => "string", :use => "optional"
      end
    end

    xsd.define_complex_type "t_address", :type => "all" do
      xsd.element "street", :type => "string"
      xsd.element "city", :type => "string"
    end

    xsd.element "customer" do
      xsd.element "customer_number", :type => "mystring"
      xsd.elements ["firstname", "lastname"], :type => "string", :minOccurs => 1

      xsd.element "addresses", :ctype => "sequence" do
        xsd.element "address", :type => "t_address"
      end
    end
  end
end

puts schema.to_xml

=> output

<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:complexType name="mystring">
    <xsd:simpleContent>
      <xsd:extension base="string">
        <xsd:attribute type="string" use="optional" name="type"/>
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>
  <xsd:complexType name="myint">
    <xsd:all>
      <xsd:extension base="integer">
        <xsd:attribute type="string" use="optional" name="type"/>
      </xsd:extension>
    </xsd:all>
  </xsd:complexType>
  <xsd:complexType name="t_address">
    <xsd:all>
      <xsd:element type="string" name="street"/>
      <xsd:element type="string" name="city"/>
    </xsd:all>
  </xsd:complexType>
  <xsd:element name="customer">
    <xsd:complexType>
      <xsd:all>
        <xsd:element type="mystring" name="customer_number"/>
        <xsd:element type="string" minOccurs="1" name="firstname"/>
        <xsd:element type="string" minOccurs="1" name="lastname"/>
        <xsd:element name="addresses">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element type="t_address" name="address"/>
            </xsd:sequence>
          </xsd:complexType>
        </xsd:element>
      </xsd:all>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

About

ruby dsl for creating xsd's

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages