-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
85 lines (73 loc) · 2.37 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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>