xsd 1.0.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -7,12 +7,12 @@ module XSD
|
|
7
7
|
class Documentation < BaseObject
|
8
8
|
# Optional. A URI reference that specifies the source of the application information
|
9
9
|
# @!attribute source
|
10
|
-
# @return
|
10
|
+
# @return String
|
11
11
|
property :source, :string
|
12
12
|
|
13
13
|
# Optional. Specifies the language used in the contents
|
14
14
|
# @!attribute xml_lang
|
15
|
-
# @return
|
15
|
+
# @return String
|
16
16
|
property :'xml:lang', :string
|
17
17
|
end
|
18
18
|
end
|
data/lib/xsd/objects/element.rb
CHANGED
@@ -14,30 +14,30 @@ module XSD
|
|
14
14
|
|
15
15
|
# Optional. Specifies the name of the attribute. Name and ref attributes cannot both be present
|
16
16
|
# @!attribute name
|
17
|
-
# @return
|
17
|
+
# @return String
|
18
18
|
property :name, :string
|
19
19
|
|
20
20
|
# Optional. Specifies either the name of a built-in data type, or the name of a simpleType or complexType element
|
21
21
|
# @!attribute type
|
22
|
-
# @return
|
22
|
+
# @return String, nil
|
23
23
|
property :type, :string
|
24
24
|
|
25
25
|
# Optional. Specifies the name of an element that can be substituted with this element. This attribute cannot be
|
26
26
|
# used if the parent element is not the schema element
|
27
27
|
# @!attribute substitution_group
|
28
|
-
# @return
|
28
|
+
# @return String, nil
|
29
29
|
property :substitutionGroup, :string
|
30
30
|
|
31
31
|
# Optional. Specifies a default value for the element (can only be used if the element's content is a simple type
|
32
32
|
# or text only)
|
33
33
|
# @!attribute default
|
34
|
-
# @return
|
34
|
+
# @return String, nil
|
35
35
|
property :default, :string
|
36
36
|
|
37
37
|
# Optional. Specifies a fixed value for the element (can only be used if the element's content is a simple type
|
38
38
|
# or text only)
|
39
39
|
# @!attribute fixed
|
40
|
-
# @return
|
40
|
+
# @return String, nil
|
41
41
|
property :fixed, :string
|
42
42
|
|
43
43
|
# Optional. Specifies the form for the element. "unqualified" indicates that this element is not required to be
|
@@ -45,21 +45,21 @@ module XSD
|
|
45
45
|
# prefix. The default value is the value of the elementFormDefault attribute of the schema element. This attribute
|
46
46
|
# cannot be used if the parent element is the schema element
|
47
47
|
# @!attribute form
|
48
|
-
# @return
|
48
|
+
# @return String
|
49
49
|
property :form, :string
|
50
50
|
|
51
51
|
# Optional. Specifies whether an explicit null value can be assigned to the element. True enables an instance of
|
52
52
|
# the element to have the null attribute set to true. The null attribute is defined as part of the XML Schema
|
53
53
|
# namespace for instances. Default is false
|
54
54
|
# @!attribute nillable
|
55
|
-
# @return
|
55
|
+
# @return Boolean
|
56
56
|
property :nillable, :boolean, default: false
|
57
57
|
|
58
58
|
# Optional. Specifies whether the element can be used in an instance document. True indicates that the element
|
59
59
|
# cannot appear in the instance document. Instead, another element whose substitutionGroup attribute contains the
|
60
60
|
# qualified name (QName) of this element must appear in this element's place. Default is false
|
61
61
|
# @!attribute abstract
|
62
|
-
# @return
|
62
|
+
# @return Boolean
|
63
63
|
property :abstract, :boolean, default: false
|
64
64
|
|
65
65
|
# Optional. Prevents an element with a specified type of derivation from being used in place of this element.
|
@@ -69,7 +69,7 @@ module XSD
|
|
69
69
|
# substitution - prevents elements derived by substitution
|
70
70
|
# #all - prevents all derived elements
|
71
71
|
# @!attribute block
|
72
|
-
# @return
|
72
|
+
# @return String, nil
|
73
73
|
property :block, :string
|
74
74
|
|
75
75
|
# Optional. Sets the default value of the final attribute on the element element. This attribute cannot be used if
|
@@ -79,50 +79,50 @@ module XSD
|
|
79
79
|
# restriction - prevents elements derived by restriction
|
80
80
|
# #all - prevents all derived elements
|
81
81
|
# @!attribute final
|
82
|
-
# @return
|
82
|
+
# @return String, nil
|
83
83
|
property :final, :string
|
84
84
|
|
85
85
|
# Nested unique objects
|
86
86
|
# @!attribute unique
|
87
|
-
# @return
|
87
|
+
# @return Array<Unique>
|
88
88
|
child :unique, [:unique]
|
89
89
|
|
90
90
|
# Determine if element is required
|
91
|
-
# @return
|
91
|
+
# @return Boolean
|
92
92
|
def required?
|
93
93
|
computed_min_occurs > 0
|
94
94
|
end
|
95
95
|
|
96
96
|
# Determine if element is optional
|
97
|
-
# @return
|
97
|
+
# @return Boolean
|
98
98
|
def optional?
|
99
99
|
!required?
|
100
100
|
end
|
101
101
|
|
102
102
|
# Determine if element may occur multiple times
|
103
|
-
# @return
|
103
|
+
# @return Boolean
|
104
104
|
def multiple_allowed?
|
105
105
|
computed_max_occurs == :unbounded || computed_max_occurs > 1
|
106
106
|
end
|
107
107
|
|
108
108
|
# Determine if element has complex content
|
109
|
-
# @return
|
109
|
+
# @return Boolean
|
110
110
|
def complex?
|
111
|
-
complex_type && !complex_type.simple_content &&
|
111
|
+
complex_type && !complex_type.simple_content && collect_elements.any?
|
112
112
|
end
|
113
113
|
|
114
114
|
# Get elements that can appear instead of this one
|
115
|
-
# @return
|
115
|
+
# @return Array<Element>
|
116
116
|
def substitution_elements
|
117
117
|
# TODO: for now we do not search in parent schemas (that imported current schema)
|
118
118
|
# TODO: refactor for better namespace handling (use xpath with namespaces or correct comparison)
|
119
|
-
schema.
|
119
|
+
schema.collect_elements.select do |element|
|
120
120
|
element.substitution_group&.split(':')&.last == name
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
124
|
# Get target namespace
|
125
|
-
# @return
|
125
|
+
# @return String
|
126
126
|
def target_namespace
|
127
127
|
schema.target_namespace
|
128
128
|
end
|
@@ -8,7 +8,26 @@ module XSD
|
|
8
8
|
TYPE_PROPERTY = nil
|
9
9
|
|
10
10
|
include Based
|
11
|
-
include SimpleTyped
|
12
11
|
include AttributeContainer
|
12
|
+
|
13
|
+
# Nested group
|
14
|
+
# @!attribute group
|
15
|
+
# @return Group
|
16
|
+
child :group, :group
|
17
|
+
|
18
|
+
# Nested all
|
19
|
+
# @!attribute all
|
20
|
+
# @return All
|
21
|
+
child :all, :all
|
22
|
+
|
23
|
+
# Nested choice
|
24
|
+
# @!attribute choice
|
25
|
+
# @return Choice
|
26
|
+
child :choice, :choice
|
27
|
+
|
28
|
+
# Nested sequence
|
29
|
+
# @!attribute sequence
|
30
|
+
# @return Sequence
|
31
|
+
child :sequence, :sequence
|
13
32
|
end
|
14
33
|
end
|
data/lib/xsd/objects/facet.rb
CHANGED
data/lib/xsd/objects/field.rb
CHANGED
data/lib/xsd/objects/group.rb
CHANGED
@@ -11,22 +11,22 @@ module XSD
|
|
11
11
|
|
12
12
|
# Optional. Specifies the name of the attribute. Name and ref attributes cannot both be present
|
13
13
|
# @!attribute name
|
14
|
-
# @return
|
14
|
+
# @return String
|
15
15
|
property :name, :string
|
16
16
|
|
17
17
|
# Nested all object
|
18
18
|
# @!attribute all
|
19
|
-
# @return
|
19
|
+
# @return All
|
20
20
|
child :all, :all
|
21
21
|
|
22
22
|
# Nested choice object
|
23
23
|
# @!attribute choice
|
24
|
-
# @return
|
24
|
+
# @return Choice
|
25
25
|
child :choice, :choice
|
26
26
|
|
27
27
|
# Nested sequence object
|
28
28
|
# @!attribute sequence
|
29
|
-
# @return
|
29
|
+
# @return Sequence
|
30
30
|
child :sequence, :sequence
|
31
31
|
end
|
32
32
|
end
|
data/lib/xsd/objects/import.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'rest-client'
|
4
|
-
|
5
3
|
module XSD
|
6
4
|
# The import element is used to add multiple schemas with different target namespace to a document.
|
7
5
|
# Parent elements: schema
|
@@ -9,59 +7,32 @@ module XSD
|
|
9
7
|
class Import < BaseObject
|
10
8
|
# Optional. Specifies the URI of the namespace to import
|
11
9
|
# @!attribute namespace
|
12
|
-
# @return
|
10
|
+
# @return String, nil
|
13
11
|
property :namespace, :string
|
14
12
|
|
15
13
|
# Optional. Specifies the URI to the schema for the imported namespace
|
16
14
|
# @!attribute schema_location
|
17
|
-
# @return
|
15
|
+
# @return String, nil
|
18
16
|
property :schemaLocation, :string
|
19
17
|
|
20
|
-
# Get imported
|
21
|
-
# @return
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
xml = if reader.imported_xsd[namespace]
|
26
|
-
# check in imported xsd by namespace
|
27
|
-
reader.imported_xsd[namespace]
|
28
|
-
elsif schema_location =~ /^https?:/
|
29
|
-
# check http(s) schema location
|
30
|
-
download_uri(schema_location)
|
31
|
-
elsif (path = local_path)
|
32
|
-
# check local relative path
|
33
|
-
path
|
34
|
-
elsif namespace =~ /^https?:/
|
35
|
-
# check http(s) namespace
|
36
|
-
# TODO: investigate spec conformance
|
37
|
-
download_uri(namespace.gsub(/#{File.basename(schema_location, '.*')}$/, '').to_s + schema_location)
|
38
|
-
else
|
39
|
-
raise ImportError, "Failed to locate import '#{schema_location}' for namespace '#{namespace}'"
|
40
|
-
end
|
41
|
-
|
42
|
-
# TODO: pass all provided options
|
43
|
-
@imported_reader = XSD::XML.new(xml, imported_xsd: reader.imported_xsd, logger: reader.logger)
|
44
|
-
end
|
45
|
-
|
46
|
-
def local_path
|
47
|
-
return unless reader.xsd.is_a?(Pathname)
|
48
|
-
|
49
|
-
path = reader.xsd.dirname.join(schema_location)
|
50
|
-
path.file? ? path : nil
|
51
|
-
end
|
18
|
+
# Get imported schema
|
19
|
+
# @return Schema
|
20
|
+
def imported_schema
|
21
|
+
known_schemas = reader.schemas_for_namespace(namespace)
|
22
|
+
return known_schemas.first if known_schemas.any?
|
52
23
|
|
53
|
-
|
24
|
+
unless schema_location
|
25
|
+
raise ImportError, "Schema location not provided for namespace '#{namespace}', use add_schema_xml()/add_schema_node()"
|
26
|
+
end
|
54
27
|
|
55
|
-
|
56
|
-
reader.
|
28
|
+
xml = reader.resource_resolver.call(schema_location, namespace)
|
29
|
+
new_schema = reader.add_schema_xml(xml)
|
57
30
|
|
58
|
-
|
59
|
-
|
60
|
-
rescue RestClient::Exception => e
|
61
|
-
raise ImportError, e.message
|
31
|
+
unless namespace == new_schema.target_namespace
|
32
|
+
raise ImportError, 'Import namespace does not match imported schema targetNamespace'
|
62
33
|
end
|
63
34
|
|
64
|
-
|
35
|
+
new_schema
|
65
36
|
end
|
66
37
|
end
|
67
38
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module XSD
|
4
|
+
# The include element is used to add multiple schemas with the same target namespace to a document.
|
5
|
+
# Parent elements: schema
|
6
|
+
# https://www.w3schools.com/xml/el_include.asp
|
7
|
+
class Include < BaseObject
|
8
|
+
# Required. Specifies the URI to the schema to include in the target namespace of the containing schema
|
9
|
+
# @!attribute schema_location
|
10
|
+
# @return String
|
11
|
+
property :schemaLocation, :string
|
12
|
+
|
13
|
+
# Get imported schema
|
14
|
+
# @return Schema
|
15
|
+
def imported_schema
|
16
|
+
# cache included schema locally as it has no unique namespace to check in global registry
|
17
|
+
return @imported_schema if @imported_schema
|
18
|
+
|
19
|
+
xml = reader.resource_resolver.call(schema_location)
|
20
|
+
new_schema = reader.add_schema_xml(xml)
|
21
|
+
|
22
|
+
unless schema.target_namespace == new_schema.target_namespace
|
23
|
+
raise ImportError, 'Schema targetNamespace does not match included schema targetNamespace'
|
24
|
+
end
|
25
|
+
|
26
|
+
@imported_schema = new_schema
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/xsd/objects/key.rb
CHANGED
@@ -9,17 +9,17 @@ module XSD
|
|
9
9
|
# The name must be a no-colon-name (NCName) as defined in the XML Namespaces specification.
|
10
10
|
# The name must be unique within an identity constraint set. Required.
|
11
11
|
# @!attribute name
|
12
|
-
# @return
|
12
|
+
# @return String
|
13
13
|
property :name, :string, required: true
|
14
14
|
|
15
15
|
# Get nested selector object
|
16
16
|
# @!attribute selector
|
17
|
-
# @return
|
17
|
+
# @return Selector
|
18
18
|
child :selector, :selector
|
19
19
|
|
20
20
|
# Get nested field objects
|
21
21
|
# @!attribute fields
|
22
|
-
# @return
|
22
|
+
# @return Array<Field>
|
23
23
|
child :fields, [:field]
|
24
24
|
end
|
25
25
|
end
|
data/lib/xsd/objects/keyref.rb
CHANGED
@@ -9,7 +9,7 @@ module XSD
|
|
9
9
|
# The name must be a no-colon-name (NCName) as defined in the XML Namespaces specification.
|
10
10
|
# The name must be unique within an identity constraint set. Required.
|
11
11
|
# @!attribute name
|
12
|
-
# @return
|
12
|
+
# @return String
|
13
13
|
property :name, :string, required: true
|
14
14
|
|
15
15
|
# The name of a key or unique element defined in this schema
|
@@ -17,17 +17,17 @@ module XSD
|
|
17
17
|
# The refer value must be a qualified name (QName).
|
18
18
|
# The type can include a namespace prefix. Required.
|
19
19
|
# @!attribute refer
|
20
|
-
# @return
|
20
|
+
# @return String
|
21
21
|
property :refer, :string, required: true
|
22
22
|
|
23
23
|
# Get nested selector object
|
24
24
|
# @!attribute selector
|
25
|
-
# @return
|
25
|
+
# @return Selector
|
26
26
|
child :selector, :selector
|
27
27
|
|
28
28
|
# Get nested field objects
|
29
29
|
# @!attribute fields
|
30
|
-
# @return
|
30
|
+
# @return Array<Field>
|
31
31
|
child :fields, [:field]
|
32
32
|
end
|
33
33
|
end
|
data/lib/xsd/objects/list.rb
CHANGED
@@ -12,7 +12,7 @@ module XSD
|
|
12
12
|
# Specifies the name of a built-in data type or simpleType element defined in this or another schema.
|
13
13
|
# This attribute is not allowed if the content contains a simpleType element, otherwise it is required
|
14
14
|
# @!attribute item_type
|
15
|
-
# @return
|
15
|
+
# @return String, nil
|
16
16
|
property :itemType, :string
|
17
17
|
end
|
18
18
|
end
|
@@ -16,8 +16,28 @@ module XSD
|
|
16
16
|
fractionDigits length minLength maxLength enumeration whiteSpace pattern
|
17
17
|
].freeze
|
18
18
|
|
19
|
+
# Nested group
|
20
|
+
# @!attribute group
|
21
|
+
# @return Group
|
22
|
+
child :group, :group
|
23
|
+
|
24
|
+
# Nested all
|
25
|
+
# @!attribute all
|
26
|
+
# @return All
|
27
|
+
child :all, :all
|
28
|
+
|
29
|
+
# Nested choice
|
30
|
+
# @!attribute choice
|
31
|
+
# @return Choice
|
32
|
+
child :choice, :choice
|
33
|
+
|
34
|
+
# Nested sequence
|
35
|
+
# @!attribute sequence
|
36
|
+
# @return Sequence
|
37
|
+
child :sequence, :sequence
|
38
|
+
|
19
39
|
# Get restriction facets
|
20
|
-
# @return
|
40
|
+
# @return Hash
|
21
41
|
def facets
|
22
42
|
nodes.inject({}) do |hash, node|
|
23
43
|
if FACET_ELEMENTS.include?(node.name)
|
@@ -40,8 +60,8 @@ module XSD
|
|
40
60
|
|
41
61
|
# Get all available elements on the current stack level, optionally including base type elements
|
42
62
|
# @param [Boolean] include_base
|
43
|
-
# @return
|
44
|
-
def
|
63
|
+
# @return Array<Element>
|
64
|
+
def collect_elements(include_base = false)
|
45
65
|
# By default we do not include base element for complex restrictions
|
46
66
|
super
|
47
67
|
end
|
data/lib/xsd/objects/schema.rb
CHANGED
@@ -13,7 +13,7 @@ module XSD
|
|
13
13
|
# are not required to be qualified with the namespace prefix. "qualified" indicates that attributes from the target
|
14
14
|
# namespace must be qualified with the namespace prefix
|
15
15
|
# @!attribute attribute_form_default
|
16
|
-
# @return
|
16
|
+
# @return String
|
17
17
|
property :attributeFormDefault, :string, default: 'unqualified'
|
18
18
|
|
19
19
|
# Optional. The form for elements declared in the target namespace of this schema. The value must be "qualified"
|
@@ -21,7 +21,7 @@ module XSD
|
|
21
21
|
# not required to be qualified with the namespace prefix. "qualified" indicates that elements from the target
|
22
22
|
# namespace must be qualified with the namespace prefix
|
23
23
|
# @!attribute element_form_default
|
24
|
-
# @return
|
24
|
+
# @return String
|
25
25
|
property :elementFormDefault, :string, default: 'unqualified'
|
26
26
|
|
27
27
|
# Optional. Specifies the default value of the block attribute on element and complexType elements in the target
|
@@ -33,7 +33,7 @@ module XSD
|
|
33
33
|
# substitution - prevents substitution of elements
|
34
34
|
# #all - prevents all derived complex types
|
35
35
|
# @!attribute block_default
|
36
|
-
# @return
|
36
|
+
# @return String
|
37
37
|
property :blockDefault, :string
|
38
38
|
|
39
39
|
# Optional. Specifies the default value of the final attribute on element, simpleType, and complexType elements in
|
@@ -46,109 +46,115 @@ module XSD
|
|
46
46
|
# union - prevents derivation by union
|
47
47
|
# #all - prevents all derivation
|
48
48
|
# @!attribute final_default
|
49
|
-
# @return
|
49
|
+
# @return String
|
50
50
|
property :finalDefault, :string
|
51
51
|
|
52
52
|
# Optional. A URI reference of the namespace of this schema
|
53
53
|
# @!attribute target_namespace
|
54
|
-
# @return
|
54
|
+
# @return String
|
55
55
|
property :targetNamespace, :string
|
56
56
|
|
57
57
|
# Optional. Specifies the version of the schema
|
58
58
|
# @!attribute version
|
59
|
-
# @return
|
59
|
+
# @return String
|
60
60
|
property :version, :string
|
61
61
|
|
62
62
|
# A URI reference that specifies one or more namespaces for use in this schema. If no prefix is assigned, the schema
|
63
63
|
# components of the namespace can be used with unqualified references
|
64
64
|
# @!attribute xmlns
|
65
|
-
# @return
|
65
|
+
# @return String
|
66
66
|
property :xmlns, :string
|
67
67
|
|
68
68
|
# Global complex types
|
69
69
|
# @!attribute complex_types
|
70
|
-
# @return
|
70
|
+
# @return Array<ComplexType>
|
71
71
|
child :complex_types, [:complexType]
|
72
72
|
|
73
73
|
# Global simple types
|
74
74
|
# @!attribute simple_types
|
75
|
-
# @return
|
75
|
+
# @return Array<SimpleType>
|
76
76
|
child :simple_types, [:simpleType]
|
77
77
|
|
78
78
|
# Global groups
|
79
79
|
# @!attribute groups
|
80
|
-
# @return
|
80
|
+
# @return Array<Group>
|
81
81
|
child :groups, [:group]
|
82
82
|
|
83
|
-
#
|
83
|
+
# Schema imports
|
84
84
|
# @!attribute imports
|
85
|
-
# @return
|
85
|
+
# @return Array<Import>
|
86
86
|
child :imports, [:import]
|
87
87
|
|
88
|
+
# Schema includes
|
89
|
+
# @!attribute includes
|
90
|
+
# @return Array<Include>
|
91
|
+
child :includes, [:include]
|
92
|
+
|
88
93
|
# Get current schema object
|
89
|
-
# @return
|
94
|
+
# @return Schema
|
90
95
|
def schema
|
91
96
|
self
|
92
97
|
end
|
93
98
|
|
94
|
-
# Get all available
|
95
|
-
# @return
|
96
|
-
def
|
99
|
+
# Get all available elements on the current stack level, for schema same as elements
|
100
|
+
# @return Array<Element>
|
101
|
+
def collect_elements(*)
|
97
102
|
elements
|
98
103
|
end
|
99
104
|
|
100
|
-
# Get all available
|
101
|
-
# @return
|
102
|
-
def
|
105
|
+
# Get all available attributes on the current stack level, for schema same as attributes
|
106
|
+
# @return Array<Attribute>
|
107
|
+
def collect_attributes(*)
|
103
108
|
attributes
|
104
109
|
end
|
105
110
|
|
106
111
|
# Get target namespace prefix. There may be more than one prefix, but we return only first defined
|
107
|
-
# @return
|
112
|
+
# @return String
|
108
113
|
def target_namespace_prefix
|
109
114
|
@target_namespace_prefix ||= namespaces.key(target_namespace)&.sub(/^xmlns:?/, '') || ''
|
110
115
|
end
|
111
116
|
|
112
117
|
# Get schema namespace prefix
|
113
|
-
# @return
|
118
|
+
# @return String
|
114
119
|
def namespace_prefix
|
115
120
|
@namespace_prefix ||= namespaces.key(XML_SCHEMA).sub(/^xmlns:?/, '')
|
116
121
|
end
|
117
122
|
|
118
123
|
# Check if namespace is a target namespace
|
119
|
-
# @param [String]
|
120
|
-
# @return
|
121
|
-
def targets_namespace?(
|
122
|
-
namespaces[
|
124
|
+
# @param [String, nil] namespace
|
125
|
+
# @return Boolean
|
126
|
+
def targets_namespace?(namespace)
|
127
|
+
namespace == target_namespace || namespaces[namespace.empty? ? 'xmlns' : "xmlns:#{namespace}"] == target_namespace
|
123
128
|
end
|
124
129
|
|
125
|
-
# Override map_children on schema to get objects from all
|
130
|
+
# Override map_children on schema to get objects from all loaded schemas
|
126
131
|
# @param [Symbol] name
|
127
|
-
# @return
|
132
|
+
# @return Array<BaseObject>
|
128
133
|
def map_children(name, cache = {})
|
129
134
|
super(name) + import_map_children(name, cache)
|
130
135
|
end
|
131
136
|
|
132
|
-
# Get children from all
|
137
|
+
# Get children from all loaded schemas
|
133
138
|
# @param [Symbol] name
|
134
|
-
# @return
|
135
|
-
# TODO: better recursion handling, may be refactor needed 1 reader for all schemas with centralized cache
|
139
|
+
# @return Array<BaseObject>
|
136
140
|
def import_map_children(name, cache)
|
137
|
-
return [] if name.to_sym
|
141
|
+
return [] if %i[import include].include?(name.to_sym)
|
138
142
|
|
139
|
-
imports.map do |import|
|
140
|
-
|
141
|
-
|
143
|
+
(includes + imports).map do |import|
|
144
|
+
key = import.respond_to?(:namespace) && import.namespace ? import.namespace : import.schema_location
|
145
|
+
if cache.key?(key)
|
142
146
|
nil
|
143
147
|
else
|
144
|
-
cache[
|
145
|
-
import.
|
148
|
+
cache[key] = true
|
149
|
+
import.imported_schema.map_children(name, cache)
|
146
150
|
end
|
147
151
|
end.compact.flatten
|
148
152
|
end
|
149
153
|
|
154
|
+
# Get import by namespace
|
155
|
+
# @return Import
|
150
156
|
def import_by_namespace(ns)
|
151
|
-
aliases = [ns, namespaces["xmlns:#{(ns || '').gsub(/^xmlns:/, '')}"]].compact
|
157
|
+
aliases = [ns, namespaces["xmlns:#{(ns || '').gsub(/^xmlns:/, '')}"], reader.namespace_prefixes[ns]].compact
|
152
158
|
imports.find { |import| aliases.include?(import.namespace) }
|
153
159
|
end
|
154
160
|
end
|
data/lib/xsd/objects/selector.rb
CHANGED
@@ -9,7 +9,7 @@ module XSD
|
|
9
9
|
# Required. Specifies an XPath expression, relative to the element being declared, that identifies the child
|
10
10
|
# elements to which the identity constraint applies
|
11
11
|
# @!attribute xpath
|
12
|
-
# @return
|
12
|
+
# @return String
|
13
13
|
property :xpath, :string, required: true
|
14
14
|
end
|
15
15
|
end
|
data/lib/xsd/objects/sequence.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
|
@@ -8,12 +8,12 @@ module XSD
|
|
8
8
|
class SimpleContent < BaseObject
|
9
9
|
# Nested extension
|
10
10
|
# @!attribute extension
|
11
|
-
# @return
|
11
|
+
# @return Extension, nil
|
12
12
|
child :extension, :extension
|
13
13
|
|
14
14
|
# Nested restriction
|
15
15
|
# @!attribute restriction
|
16
|
-
# @return
|
16
|
+
# @return Restriction, nil
|
17
17
|
child :restriction, :restriction
|
18
18
|
end
|
19
19
|
end
|