xsd 1.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile +9 -0
- data/README.md +14 -4
- data/lib/xsd/base_object.rb +43 -40
- data/lib/xsd/generator.rb +7 -7
- data/lib/xsd/objects/all.rb +2 -2
- data/lib/xsd/objects/annotation.rb +2 -2
- data/lib/xsd/objects/any.rb +2 -2
- data/lib/xsd/objects/any_attribute.rb +2 -2
- data/lib/xsd/objects/appinfo.rb +1 -1
- data/lib/xsd/objects/attribute.rb +9 -9
- data/lib/xsd/objects/attribute_group.rb +1 -1
- data/lib/xsd/objects/choice.rb +4 -4
- data/lib/xsd/objects/complex_content.rb +3 -3
- data/lib/xsd/objects/complex_type.rb +12 -12
- data/lib/xsd/objects/documentation.rb +2 -2
- data/lib/xsd/objects/element.rb +19 -19
- data/lib/xsd/objects/extension.rb +20 -1
- data/lib/xsd/objects/facet.rb +1 -1
- data/lib/xsd/objects/field.rb +1 -1
- data/lib/xsd/objects/group.rb +4 -4
- data/lib/xsd/objects/import.rb +15 -44
- data/lib/xsd/objects/include.rb +29 -0
- data/lib/xsd/objects/key.rb +3 -3
- data/lib/xsd/objects/keyref.rb +4 -4
- data/lib/xsd/objects/list.rb +1 -1
- data/lib/xsd/objects/restriction.rb +23 -3
- data/lib/xsd/objects/schema.rb +43 -37
- data/lib/xsd/objects/selector.rb +1 -1
- data/lib/xsd/objects/sequence.rb +4 -4
- data/lib/xsd/objects/simple_content.rb +2 -2
- data/lib/xsd/objects/simple_type.rb +5 -5
- data/lib/xsd/objects/union.rb +2 -2
- data/lib/xsd/objects/unique.rb +2 -2
- data/lib/xsd/shared/attribute_container.rb +2 -2
- data/lib/xsd/shared/based.rb +9 -9
- data/lib/xsd/shared/complex_typed.rb +7 -7
- data/lib/xsd/shared/element_container.rb +1 -1
- data/lib/xsd/shared/min_max_occurs.rb +4 -4
- data/lib/xsd/shared/referenced.rb +3 -3
- data/lib/xsd/shared/simple_typed.rb +1 -1
- data/lib/xsd/validator.rb +1 -1
- data/lib/xsd/version.rb +1 -1
- data/lib/xsd/xml.rb +107 -31
- data/lib/xsd.rb +1 -0
- data/xsd.gemspec +0 -8
- metadata +3 -100
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3b12830c536c37e72b109727f470d45de29b6c852e62476cd3aa5578dd3b9c7
|
4
|
+
data.tar.gz: 248b65a3794a6c83a6aca695b0d565d55b971991272fd5f7f0a8a841fb8847ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac15d2c2c163bd70f007fd76b5c007fbc786ed09d5609a2d6dba5aa8836144917a5159a32c1b7f47aa250bd18034d8339f445180fc4cd330745138ec60283e32
|
7
|
+
data.tar.gz: 7db0b9ac2ba0c97aab16d84db5145b4a8a18c901f3c24c8fd13a73b96a1998083a41cff38c3b0f7098dc53457b693e0ee5d3d941ceb1712f38a54924d32ce544
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [2.1.0] - 2023-07-10
|
4
|
+
|
5
|
+
- Add support for <xs:include> element
|
6
|
+
- Changed method "schema_for_namespace(namespace) -> XSD::Schema" signature to "schemas_for_namespace(namespace) -> Array<XSD::Schema>"
|
7
|
+
|
8
|
+
## [2.0.0] - 2023-07-07
|
9
|
+
|
10
|
+
- Change XSD::XML.new(file, **options) -> XSD::XML.open(file, **options)
|
11
|
+
- Add ability to construct empty reader (reader = XSD::XML.new(**options)) and manually add schemas to it (reader.add_schema_xml(xml))
|
12
|
+
- Add ability to configure import resources resolver via options
|
13
|
+
|
3
14
|
## [1.0.0] - 2023-04-25
|
4
15
|
|
5
16
|
- Initial release
|
data/Gemfile
CHANGED
@@ -4,3 +4,12 @@ source 'https://rubygems.org'
|
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in xsd_to_json.gemspec
|
6
6
|
gemspec
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem 'logger', '~> 1.5'
|
10
|
+
gem 'rspec', '~> 3.12'
|
11
|
+
gem 'rubocop', '~> 1.50'
|
12
|
+
gem 'rubocop-performance', '~> 1.17'
|
13
|
+
gem 'rubocop-rake', '~> 0.6'
|
14
|
+
gem 'rubocop-rspec', '~> 2.10'
|
15
|
+
end
|
data/README.md
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# XSD
|
2
|
-
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/xsd.svg)][gem]
|
3
3
|
[![Ruby](https://github.com/ekzo-dev/ruby-xsd/actions/workflows/main.yml/badge.svg)][githubactions]
|
4
4
|
|
5
|
+
[gem]: https://badge.fury.io/rb/xsd
|
5
6
|
[githubactions]: https://github.com/omniauth/omniauth/actions/workflows/main.yml
|
6
7
|
|
7
8
|
The Ruby XSD library is an [XML Schema](https://www.w3.org/2001/XMLSchema) implementation for Ruby. Provides easy and
|
@@ -25,22 +26,31 @@ gem 'xsd'
|
|
25
26
|
require 'xsd'
|
26
27
|
|
27
28
|
# Load ruby-xsd
|
28
|
-
reader = XSD::XML.
|
29
|
+
reader = XSD::XML.open('some.xsd')
|
30
|
+
|
31
|
+
# Get elements and their child elements
|
32
|
+
element = reader['NewReleaseMessage']
|
33
|
+
element.collect_elements.map(&:name) # => ['MessageHeader', 'UpdateIndicator', 'IsBackfill', 'CatalogTransfer', 'WorkList', 'CueSheetList', 'ResourceList', 'CollectionList', 'ReleaseList', 'DealList']
|
29
34
|
|
30
35
|
# Get attributes
|
31
36
|
attribute = reader['NewReleaseMessage']['@MessageSchemaVersionId']
|
32
37
|
|
33
|
-
# Get
|
38
|
+
# Get attribute information
|
34
39
|
attribute.name # => 'MessageSchemaVersionId'
|
35
40
|
attribute.type # => 'xs:string'
|
36
41
|
attribute.required? # => true
|
42
|
+
attribute.optional? # => false
|
43
|
+
attribute.prohibited? # => true
|
37
44
|
|
38
45
|
# Get element information
|
39
|
-
element = reader['NewReleaseMessage']['ResourceList']['SoundRecording']
|
46
|
+
element = reader['NewReleaseMessage']['ResourceList']['SoundRecording'] # => XSD::Element
|
40
47
|
element.min_occurs # => 0
|
41
48
|
element.max_occurs # => :unbounded
|
42
49
|
element.type # => 'ern:SoundRecording'
|
43
50
|
element.complex_type # => XSD::ComplexType
|
51
|
+
element.complex? # => true
|
52
|
+
element.multiple_allowed? # => true
|
53
|
+
element.required? # => false
|
44
54
|
```
|
45
55
|
|
46
56
|
## Development
|
data/lib/xsd/base_object.rb
CHANGED
@@ -34,7 +34,7 @@ module XSD
|
|
34
34
|
|
35
35
|
# Optional. Specifies a unique ID for the element
|
36
36
|
# @!attribute id
|
37
|
-
# @return
|
37
|
+
# @return String
|
38
38
|
# property :id, :string
|
39
39
|
def id
|
40
40
|
node['id']
|
@@ -48,39 +48,39 @@ module XSD
|
|
48
48
|
end
|
49
49
|
|
50
50
|
# Get current XML node
|
51
|
-
# @return
|
51
|
+
# @return Nokogiri::XML::Node
|
52
52
|
def node
|
53
53
|
options[:node]
|
54
54
|
end
|
55
55
|
|
56
56
|
# Get current namespaces
|
57
|
-
# @return
|
57
|
+
# @return Hash
|
58
58
|
def namespaces
|
59
59
|
node.namespaces || {}
|
60
60
|
end
|
61
61
|
|
62
62
|
# Get child nodes
|
63
63
|
# @param [Symbol] name
|
64
|
-
# @return
|
64
|
+
# @return Nokogiri::XML::NodeSet
|
65
65
|
def nodes(name = :*)
|
66
66
|
node.xpath("./xs:#{name}", { 'xs' => XML_SCHEMA })
|
67
67
|
end
|
68
68
|
|
69
|
-
# Get schema
|
70
|
-
# @param [String]
|
71
|
-
# @return
|
72
|
-
def
|
73
|
-
if schema.targets_namespace?(
|
74
|
-
schema
|
75
|
-
elsif (import = schema.import_by_namespace(
|
76
|
-
import.
|
69
|
+
# Get schema by namespace or namespace prefix
|
70
|
+
# @param [String, nil] namespace
|
71
|
+
# @return Array<Schema>
|
72
|
+
def schemas_for_namespace(namespace)
|
73
|
+
if schema.targets_namespace?(namespace)
|
74
|
+
[schema, *schema.includes.map(&:imported_schema)]
|
75
|
+
elsif (import = schema.import_by_namespace(namespace))
|
76
|
+
[import.imported_schema]
|
77
77
|
else
|
78
|
-
raise Error, "Schema not found for namespace '#{
|
78
|
+
raise Error, "Schema not found for namespace '#{namespace}' in '#{schema.id || schema.target_namespace}'"
|
79
79
|
end
|
80
80
|
end
|
81
81
|
|
82
82
|
# Get element or attribute by path
|
83
|
-
# @return
|
83
|
+
# @return Element, Attribute, nil
|
84
84
|
def [](*args)
|
85
85
|
result = self
|
86
86
|
|
@@ -90,9 +90,9 @@ module XSD
|
|
90
90
|
curname = curname.to_s
|
91
91
|
|
92
92
|
if curname[0] == '@'
|
93
|
-
result = result.
|
93
|
+
result = result.collect_attributes.find { |attr| attr.name == curname[1..-1] }
|
94
94
|
else
|
95
|
-
result = result.
|
95
|
+
result = result.collect_elements.find { |elem| elem.name == curname }
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
@@ -102,7 +102,7 @@ module XSD
|
|
102
102
|
# Search node by name in all available schemas and return its object
|
103
103
|
# @param [Symbol] node_name
|
104
104
|
# @param [String] name
|
105
|
-
# @return
|
105
|
+
# @return BaseObject, nil
|
106
106
|
def object_by_name(node_name, name)
|
107
107
|
# get prefix and local name
|
108
108
|
name_prefix = get_prefix(name)
|
@@ -112,17 +112,20 @@ module XSD
|
|
112
112
|
return nil if schema.namespace_prefix == name_prefix
|
113
113
|
|
114
114
|
# determine schema for namespace
|
115
|
-
|
115
|
+
search_schemas = schemas_for_namespace(name_prefix)
|
116
116
|
|
117
117
|
# find element in target schema
|
118
|
-
|
118
|
+
search_schemas.each do |s|
|
119
|
+
node = s.node.xpath("./xs:#{node_name}[@name=\"#{name_local}\"]", { 'xs' => XML_SCHEMA }).first
|
120
|
+
return s.node_to_object(node) if node
|
121
|
+
end
|
119
122
|
|
120
|
-
|
123
|
+
nil
|
121
124
|
end
|
122
125
|
|
123
126
|
# Get reader object for node
|
124
127
|
# @param [Nokogiri::XML::Node]
|
125
|
-
# @return
|
128
|
+
# @return BaseObject
|
126
129
|
def node_to_object(node)
|
127
130
|
# check object in cache first
|
128
131
|
# TODO: проверить работу!
|
@@ -135,66 +138,66 @@ module XSD
|
|
135
138
|
end
|
136
139
|
|
137
140
|
# Get xml parent object
|
138
|
-
# @return
|
141
|
+
# @return BaseObject, nil
|
139
142
|
def parent
|
140
143
|
node.respond_to?(:parent) && node.parent ? node_to_object(node.parent) : nil
|
141
144
|
end
|
142
145
|
|
143
146
|
# Get current schema object
|
144
|
-
# @return
|
147
|
+
# @return Schema
|
145
148
|
def schema
|
146
149
|
options[:schema]
|
147
150
|
end
|
148
151
|
|
149
152
|
# Get child objects
|
150
153
|
# @param [Symbol] name
|
151
|
-
# @return
|
154
|
+
# @return Array<BaseObject>
|
152
155
|
def map_children(name)
|
153
156
|
nodes(name).map { |node| node_to_object(node) }
|
154
157
|
end
|
155
158
|
|
156
159
|
# Get child object
|
157
160
|
# @param [Symbol] name
|
158
|
-
# @return
|
161
|
+
# @return BaseObject, nil
|
159
162
|
def map_child(name)
|
160
163
|
map_children(name).first
|
161
164
|
end
|
162
165
|
|
163
166
|
# Strip namespace prefix from node name
|
164
167
|
# @param [String, nil] name Name to strip from
|
165
|
-
# @return
|
168
|
+
# @return String, nil
|
166
169
|
def strip_prefix(name)
|
167
170
|
name&.include?(':') ? name.split(':').last : name
|
168
171
|
end
|
169
172
|
|
170
173
|
# Get namespace prefix from node name
|
171
174
|
# @param [String, nil] name Name to strip from
|
172
|
-
# @return
|
175
|
+
# @return String, nil
|
173
176
|
def get_prefix(name)
|
174
|
-
name&.include?(':') ? name.split(':').first :
|
177
|
+
name&.include?(':') ? name.split(':').first : nil
|
175
178
|
end
|
176
179
|
|
177
180
|
# Return element documentation
|
178
|
-
# @return
|
181
|
+
# @return Array<String>
|
179
182
|
def documentation
|
180
183
|
documentation_for(node)
|
181
184
|
end
|
182
185
|
|
183
186
|
# Return documentation for specified node
|
184
187
|
# @param [Nokogiri::XML::Node] node
|
185
|
-
# @return
|
188
|
+
# @return Array<String>
|
186
189
|
def documentation_for(node)
|
187
190
|
node.xpath('./xs:annotation/xs:documentation/text()', { 'xs' => XML_SCHEMA }).map(&:to_s).map(&:strip)
|
188
191
|
end
|
189
192
|
|
190
193
|
# Get all available elements on the current stack level
|
191
|
-
# @return
|
192
|
-
def
|
194
|
+
# @return Array<Element>
|
195
|
+
def collect_elements(*)
|
193
196
|
# exclude element that can not have elements
|
194
197
|
return [] if NO_ELEMENTS_CONTAINER.include?(self.class.mapped_name)
|
195
198
|
|
196
199
|
if is_a?(Referenced) && ref
|
197
|
-
reference.
|
200
|
+
reference.collect_elements
|
198
201
|
else
|
199
202
|
# map children recursive
|
200
203
|
map_children(:*).map do |obj|
|
@@ -202,20 +205,20 @@ module XSD
|
|
202
205
|
obj
|
203
206
|
else
|
204
207
|
# get elements considering references
|
205
|
-
(obj.is_a?(Referenced) && obj.ref ? obj.reference : obj).
|
208
|
+
(obj.is_a?(Referenced) && obj.ref ? obj.reference : obj).collect_elements
|
206
209
|
end
|
207
210
|
end.flatten
|
208
211
|
end
|
209
212
|
end
|
210
213
|
|
211
214
|
# Get all available attributes on the current stack level
|
212
|
-
# @return
|
213
|
-
def
|
215
|
+
# @return Array<Attribute>
|
216
|
+
def collect_attributes(*)
|
214
217
|
# exclude element that can not have elements
|
215
218
|
return [] if NO_ATTRIBUTES_CONTAINER.include?(self.class.mapped_name)
|
216
219
|
|
217
220
|
if is_a?(Referenced) && ref
|
218
|
-
reference.
|
221
|
+
reference.collect_attributes
|
219
222
|
else
|
220
223
|
# map children recursive
|
221
224
|
map_children(:*).map do |obj|
|
@@ -223,14 +226,14 @@ module XSD
|
|
223
226
|
obj
|
224
227
|
else
|
225
228
|
# get attributes considering references
|
226
|
-
(obj.is_a?(Referenced) && obj.ref ? obj.reference : obj).
|
229
|
+
(obj.is_a?(Referenced) && obj.ref ? obj.reference : obj).collect_attributes
|
227
230
|
end
|
228
231
|
end.flatten
|
229
232
|
end
|
230
233
|
end
|
231
234
|
|
232
235
|
# Get reader instance
|
233
|
-
# @return
|
236
|
+
# @return XML
|
234
237
|
def reader
|
235
238
|
options[:reader]
|
236
239
|
end
|
@@ -334,7 +337,7 @@ module XSD
|
|
334
337
|
end
|
335
338
|
|
336
339
|
# Get mapped element name
|
337
|
-
# @return
|
340
|
+
# @return Symbol
|
338
341
|
def self.mapped_name
|
339
342
|
# @mapped_name ||= XML::CLASS_MAP.each { |k, v| return k.to_sym if v == self }
|
340
343
|
@mapped_name ||= begin
|
data/lib/xsd/generator.rb
CHANGED
@@ -8,7 +8,7 @@ module XSD
|
|
8
8
|
# @param [Hash] data
|
9
9
|
# @param [String, Array<String>] element
|
10
10
|
# @param [Builder::XmlMarkup] builder
|
11
|
-
# @return
|
11
|
+
# @return Builder::XmlMarkup
|
12
12
|
def generate(data, element = nil, builder = nil)
|
13
13
|
# find root element
|
14
14
|
root = find_root_element(element)
|
@@ -59,13 +59,13 @@ module XSD
|
|
59
59
|
# configure namespaces
|
60
60
|
# TODO: попытаться использовать collect_namespaces?
|
61
61
|
attributes = {}
|
62
|
-
|
62
|
+
collect_attributes = element.collect_attributes
|
63
63
|
if element.complex?
|
64
|
-
|
64
|
+
collect_elements = element.collect_elements
|
65
65
|
|
66
66
|
# get namespaces for current element and it's children
|
67
67
|
prefix = nil
|
68
|
-
[*
|
68
|
+
[*collect_elements, element].each do |elem|
|
69
69
|
prefix = get_namespace_prefix(elem, attributes, namespaces)
|
70
70
|
end
|
71
71
|
else
|
@@ -75,7 +75,7 @@ module XSD
|
|
75
75
|
# iterate through each item
|
76
76
|
data.each do |item|
|
77
77
|
# prepare attributes
|
78
|
-
|
78
|
+
collect_attributes.each do |attribute|
|
79
79
|
value = item["@#{attribute.name}"]
|
80
80
|
if value
|
81
81
|
attributes[attribute.name] = value
|
@@ -88,7 +88,7 @@ module XSD
|
|
88
88
|
if element.complex?
|
89
89
|
# generate tag recursively
|
90
90
|
xml.tag!("#{prefix}:#{element.name}", attributes) do
|
91
|
-
|
91
|
+
collect_elements.each do |elem|
|
92
92
|
build_element(xml, elem, item, namespaces.dup)
|
93
93
|
end
|
94
94
|
end
|
@@ -103,7 +103,7 @@ module XSD
|
|
103
103
|
# @param [Element] element
|
104
104
|
# @param [Hash] attributes
|
105
105
|
# @param [Hash] namespaces
|
106
|
-
# @return
|
106
|
+
# @return String
|
107
107
|
def get_namespace_prefix(element, attributes, namespaces)
|
108
108
|
namespace = (element.referenced? ? element.reference : element).target_namespace
|
109
109
|
prefix = namespaces.key(namespace)
|
data/lib/xsd/objects/all.rb
CHANGED
@@ -11,12 +11,12 @@ module XSD
|
|
11
11
|
|
12
12
|
# Optional. Specifies the minimum number of times the element can occur. The value can be 0 or 1. Default value is 1
|
13
13
|
# @!attribute min_occurs
|
14
|
-
# @return
|
14
|
+
# @return Integer
|
15
15
|
property :minOccurs, :integer, default: 1
|
16
16
|
|
17
17
|
# Optional. Specifies the maximum number of times the element can occur. The value must be 1.
|
18
18
|
# @!attribute max_occurs
|
19
|
-
# @return
|
19
|
+
# @return Integer
|
20
20
|
property :maxOccurs, :integer, default: 1
|
21
21
|
end
|
22
22
|
end
|
@@ -8,12 +8,12 @@ module XSD
|
|
8
8
|
class Annotation < BaseObject
|
9
9
|
# Nested appinfos
|
10
10
|
# @!attribute appinfos
|
11
|
-
# @return
|
11
|
+
# @return Array<Appinfo>
|
12
12
|
child :appinfos, [:appinfo]
|
13
13
|
|
14
14
|
# Nested documentations
|
15
15
|
# @!attribute documentations
|
16
|
-
# @return
|
16
|
+
# @return Array<Documentation>
|
17
17
|
child :documentations, [:documentation]
|
18
18
|
end
|
19
19
|
end
|
data/lib/xsd/objects/any.rb
CHANGED
@@ -15,7 +15,7 @@ module XSD
|
|
15
15
|
# List of {URI references of namespaces, ##targetNamespace, ##local} - elements from a space-delimited list of
|
16
16
|
# the namespaces can be present
|
17
17
|
# @!attribute namespace
|
18
|
-
# @return
|
18
|
+
# @return String
|
19
19
|
property :namespace, :string, default: '##any'
|
20
20
|
|
21
21
|
# Optional. Specifies how the XML processor should handle validation against the elements specified by this any
|
@@ -25,7 +25,7 @@ module XSD
|
|
25
25
|
# lax - same as strict but; if the schema cannot be obtained, no errors will occur
|
26
26
|
# skip - The XML processor does not attempt to validate any elements from the specified namespaces
|
27
27
|
# @!attribute process_contents
|
28
|
-
# @return
|
28
|
+
# @return String, nil
|
29
29
|
property :processContents, :string, default: 'strict'
|
30
30
|
end
|
31
31
|
end
|
@@ -14,7 +14,7 @@ module XSD
|
|
14
14
|
# List of {URI references of namespaces, ##targetNamespace, ##local} - attributes from a space-delimited list
|
15
15
|
# of the namespaces can be present
|
16
16
|
# @!attribute namespace
|
17
|
-
# @return
|
17
|
+
# @return String
|
18
18
|
property :namespace, :string, default: '##any'
|
19
19
|
|
20
20
|
# Optional. Specifies how the XML processor should handle validation against the elements specified by this any
|
@@ -24,7 +24,7 @@ module XSD
|
|
24
24
|
# lax - same as strict but; if the schema cannot be obtained, no errors will occur
|
25
25
|
# skip - The XML processor does not attempt to validate any elements from the specified namespaces
|
26
26
|
# @!attribute process_contents
|
27
|
-
# @return
|
27
|
+
# @return String, nil
|
28
28
|
property :processContents, :string, default: 'strict'
|
29
29
|
end
|
30
30
|
end
|
data/lib/xsd/objects/appinfo.rb
CHANGED
@@ -13,17 +13,17 @@ module XSD
|
|
13
13
|
|
14
14
|
# Optional. Specifies the name of the attribute. Name and ref attributes cannot both be present
|
15
15
|
# @!attribute name
|
16
|
-
# @return
|
16
|
+
# @return String
|
17
17
|
property :name, :string
|
18
18
|
|
19
19
|
# Optional. Specifies a default value for the attribute. Default and fixed attributes cannot both be present
|
20
20
|
# @!attribute default
|
21
|
-
# @return
|
21
|
+
# @return String, nil
|
22
22
|
property :default, :string
|
23
23
|
|
24
24
|
# Optional. Specifies a fixed value for the attribute. Default and fixed attributes cannot both be present
|
25
25
|
# @!attribute fixed
|
26
|
-
# @return
|
26
|
+
# @return String, nil
|
27
27
|
property :fixed, :string
|
28
28
|
|
29
29
|
# Optional. Specifies the form for the attribute. The default value is the value of the attributeFormDefault
|
@@ -33,14 +33,14 @@ module XSD
|
|
33
33
|
# unqualified - indicates that this attribute is not required to be qualified with the namespace prefix and is
|
34
34
|
# matched against the (NCName) of the attribute
|
35
35
|
# @!attribute form
|
36
|
-
# @return
|
36
|
+
# @return String, nil
|
37
37
|
# TODO: поддержка default значения с вычислением родителя
|
38
38
|
property :form, :string
|
39
39
|
|
40
40
|
# Optional. Specifies a built-in data type or a simple type. The type attribute can only be present when the
|
41
41
|
# content does not contain a simpleType element
|
42
42
|
# @!attribute type
|
43
|
-
# @return
|
43
|
+
# @return String, nil
|
44
44
|
property :type, :string
|
45
45
|
|
46
46
|
# Optional. Specifies how the attribute is used. Can be one of the following values:
|
@@ -48,23 +48,23 @@ module XSD
|
|
48
48
|
# prohibited - the attribute cannot be used
|
49
49
|
# required - the attribute is required
|
50
50
|
# @!attribute use
|
51
|
-
# @return
|
51
|
+
# @return String
|
52
52
|
property :use, :string, default: 'optional'
|
53
53
|
|
54
54
|
# Determine if attribute is required
|
55
|
-
# @return
|
55
|
+
# @return Boolean
|
56
56
|
def required?
|
57
57
|
use == 'required'
|
58
58
|
end
|
59
59
|
|
60
60
|
# Determine if attribute is optional
|
61
|
-
# @return
|
61
|
+
# @return Boolean
|
62
62
|
def optional?
|
63
63
|
use == 'optional'
|
64
64
|
end
|
65
65
|
|
66
66
|
# Determine if attribute is prohibited
|
67
|
-
# @return
|
67
|
+
# @return Boolean
|
68
68
|
def prohibited?
|
69
69
|
use == 'prohibited'
|
70
70
|
end
|
data/lib/xsd/objects/choice.rb
CHANGED
@@ -12,22 +12,22 @@ module XSD
|
|
12
12
|
|
13
13
|
# Nested groups
|
14
14
|
# @!attribute groups
|
15
|
-
# @return
|
15
|
+
# @return Array<Group>
|
16
16
|
child :groups, [:group]
|
17
17
|
|
18
18
|
# Nested choices
|
19
19
|
# @!attribute choices
|
20
|
-
# @return
|
20
|
+
# @return Array<Choice>
|
21
21
|
child :choices, [:choice]
|
22
22
|
|
23
23
|
# Nested sequences
|
24
24
|
# @!attribute sequences
|
25
|
-
# @return
|
25
|
+
# @return Array<Sequence>
|
26
26
|
child :sequences, [:sequence]
|
27
27
|
|
28
28
|
# Nested anys
|
29
29
|
# @!attribute anys
|
30
|
-
# @return
|
30
|
+
# @return Array<Any>
|
31
31
|
child :anys, [:any]
|
32
32
|
end
|
33
33
|
end
|
@@ -9,17 +9,17 @@ module XSD
|
|
9
9
|
# Optional. Specifies whether character data is allowed to appear between the child elements of this complexType
|
10
10
|
# element. Default is false
|
11
11
|
# @!attribute mixed
|
12
|
-
# @return
|
12
|
+
# @return Boolean
|
13
13
|
property :mixed, :boolean, default: false
|
14
14
|
|
15
15
|
# Get nested extension
|
16
16
|
# @!attribute extension
|
17
|
-
# @return
|
17
|
+
# @return Extension, nil
|
18
18
|
child :extension, :extension
|
19
19
|
|
20
20
|
# Get nested restriction
|
21
21
|
# @!attribute restriction
|
22
|
-
# @return
|
22
|
+
# @return Restriction, nil
|
23
23
|
child :restriction, :restriction
|
24
24
|
end
|
25
25
|
end
|
@@ -10,19 +10,19 @@ module XSD
|
|
10
10
|
|
11
11
|
# Optional. Specifies the name of the attribute. Name and ref attributes cannot both be present
|
12
12
|
# @!attribute name
|
13
|
-
# @return
|
13
|
+
# @return String
|
14
14
|
property :name, :string
|
15
15
|
|
16
16
|
# Optional. Specifies whether the complex type can be used in an instance document. True indicates that an element
|
17
17
|
# cannot use this complex type directly but must use a complex type derived from this complex type. Default is false
|
18
18
|
# @!attribute abstract
|
19
|
-
# @return
|
19
|
+
# @return Boolean
|
20
20
|
property :abstract, :boolean, default: false
|
21
21
|
|
22
22
|
# Optional. Specifies whether character data is allowed to appear between the child elements of this complexType
|
23
23
|
# element. Default is false. If a simpleContent element is a child element, the mixed attribute is not allowed!
|
24
24
|
# @!attribute mixed
|
25
|
-
# @return
|
25
|
+
# @return Boolean
|
26
26
|
property :mixed, :boolean, default: false
|
27
27
|
|
28
28
|
# Optional. Prevents a complex type that has a specified type of derivation from being used in place of this
|
@@ -31,7 +31,7 @@ module XSD
|
|
31
31
|
# restriction - prevents complex types derived by restriction
|
32
32
|
# #all - prevents all derived complex types
|
33
33
|
# @!attribute block
|
34
|
-
# @return
|
34
|
+
# @return String, nil
|
35
35
|
property :block, :string
|
36
36
|
|
37
37
|
# Optional. Prevents a specified type of derivation of this complex type element. Can contain #all or a list
|
@@ -40,41 +40,41 @@ module XSD
|
|
40
40
|
# restriction - prevents derivation by restriction
|
41
41
|
# #all - prevents all derivation
|
42
42
|
# @!attribute final
|
43
|
-
# @return
|
43
|
+
# @return String, nil
|
44
44
|
property :final, :string
|
45
45
|
|
46
46
|
# Simple content object
|
47
47
|
# @!attribute simple_content
|
48
|
-
# @return
|
48
|
+
# @return SimpleContent
|
49
49
|
child :simple_content, :simpleContent
|
50
50
|
|
51
51
|
# Complex content object
|
52
52
|
# @!attribute complex_content
|
53
|
-
# @return
|
53
|
+
# @return ComplexContent
|
54
54
|
child :complex_content, :complexContent
|
55
55
|
|
56
56
|
# Nested group
|
57
57
|
# @!attribute group
|
58
|
-
# @return
|
58
|
+
# @return Group
|
59
59
|
child :group, :group
|
60
60
|
|
61
61
|
# Nested all
|
62
62
|
# @!attribute all
|
63
|
-
# @return
|
63
|
+
# @return All
|
64
64
|
child :all, :all
|
65
65
|
|
66
66
|
# Nested choice
|
67
67
|
# @!attribute choice
|
68
|
-
# @return
|
68
|
+
# @return Choice
|
69
69
|
child :choice, :choice
|
70
70
|
|
71
71
|
# Nested sequence
|
72
72
|
# @!attribute sequence
|
73
|
-
# @return
|
73
|
+
# @return Sequence
|
74
74
|
child :sequence, :sequence
|
75
75
|
|
76
76
|
# Determine if this is a linked type
|
77
|
-
# @return
|
77
|
+
# @return Boolean
|
78
78
|
def linked?
|
79
79
|
!name.nil?
|
80
80
|
end
|