Class: XSD::Element
- Inherits:
-
BaseObject
- Object
- BaseObject
- XSD::Element
- Includes:
- ComplexTyped, MinMaxOccurs, Named, Referenced, SimpleTyped
- Defined in:
- lib/xsd/objects/element.rb
Overview
The element element defines an element. Parent elements: schema, choice, all, sequence, group www.w3schools.com/xml/el_element.asp
Constant Summary collapse
- TYPE_PROPERTY =
:type
Constants inherited from BaseObject
BaseObject::NO_ATTRIBUTES_CONTAINER, BaseObject::NO_ELEMENTS_CONTAINER, BaseObject::XML_SCHEMA
Instance Attribute Summary collapse
-
#abstract ⇒ Object
Optional.
-
#block ⇒ Object
Optional.
-
#default ⇒ Object
Optional.
-
#final ⇒ Object
Optional.
-
#fixed ⇒ Object
Optional.
-
#form ⇒ Object
Optional.
-
#name ⇒ Object
Optional.
-
#nillable ⇒ Object
Optional.
-
#substitution_group ⇒ Object
Optional.
-
#type ⇒ Object
Optional.
-
#unique ⇒ Object
Nested unique objects.
Attributes included from Referenced
Attributes included from ComplexTyped
Attributes included from SimpleTyped
Attributes included from MinMaxOccurs
Attributes inherited from BaseObject
Instance Method Summary collapse
-
#attributes? ⇒ Boolean
Determine if element has attributes.
-
#complex_content? ⇒ Boolean
Determine if element has complex content.
-
#data_type ⇒ Object
Get base data type.
-
#global? ⇒ Boolean
Check is this attribute is global (immediate child of schema element).
-
#mixed_content? ⇒ Boolean
Determine if element has mixed content.
-
#optional? ⇒ Boolean
Determine if element is optional.
-
#required? ⇒ Boolean
Determine if element is required.
-
#simple_content? ⇒ Boolean
Determine if element has simple content.
-
#substitutable_elements ⇒ Object
Get substitutable elements.
Methods included from Named
Methods included from Referenced
Methods included from ComplexTyped
#collect_attributes, #collect_elements, included
Methods included from SimpleTyped
Methods included from MinMaxOccurs
#computed_max_occurs, #computed_min_occurs, included, #multiple?, #multiple_allowed?
Methods inherited from BaseObject
#[], #collect_attributes, #collect_elements, #documentation, #documentation_for, #get_prefix, #initialize, #inspect, #map_child, #map_children, #namespaces, #node, #node_to_object, #nodes, #object_by_name, #parent, #reader, #schema, #schemas_for_namespace, #strip_prefix
Constructor Details
This class inherits a constructor from XSD::BaseObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class XSD::BaseObject
Instance Attribute Details
#abstract ⇒ Object
Optional. Specifies whether the element can be used in an instance document. True indicates that the element cannot appear in the instance document. Instead, another element whose substitutionGroup attribute contains the qualified name (QName) of this element must appear in this element’s place. Default is false
64 |
# File 'lib/xsd/objects/element.rb', line 64 property :abstract, :boolean, default: false |
#block ⇒ Object
Optional. Prevents an element with a specified type of derivation from being used in place of this element. This value can contain #all or a list that is a subset of extension, restriction, or equivClass:
extension - prevents elements derived by extension
restriction - prevents elements derived by restriction
substitution - prevents elements derived by substitution
#all - prevents all derived elements
74 |
# File 'lib/xsd/objects/element.rb', line 74 property :block, :string |
#default ⇒ Object
Optional. Specifies a default value for the element (can only be used if the element’s content is a simple type or text only)
36 |
# File 'lib/xsd/objects/element.rb', line 36 property :default, :string |
#final ⇒ Object
Optional. Sets the default value of the final attribute on the element element. This attribute cannot be used if the parent element is not the schema element. This value can contain #all or a list that is a subset of extension or restriction:
extension - prevents elements derived by extension
restriction - prevents elements derived by restriction
#all - prevents all derived elements
84 |
# File 'lib/xsd/objects/element.rb', line 84 property :final, :string |
#fixed ⇒ Object
Optional. Specifies a fixed value for the element (can only be used if the element’s content is a simple type or text only)
42 |
# File 'lib/xsd/objects/element.rb', line 42 property :fixed, :string |
#form ⇒ Object
Optional. Specifies the form for the element. “unqualified” indicates that this element is not required to be qualified with the namespace prefix. “qualified” indicates that this element must be qualified with the namespace prefix. The default value is the value of the elementFormDefault attribute of the schema element. This attribute cannot be used if the parent element is the schema element
50 |
# File 'lib/xsd/objects/element.rb', line 50 property :form, :string, default: proc { schema.element_form_default } |
#name ⇒ Object
Optional. Specifies a name for the element. This attribute is required if the parent element is the schema element
19 |
# File 'lib/xsd/objects/element.rb', line 19 property :name, :string |
#nillable ⇒ Object
Optional. Specifies whether an explicit null value can be assigned to the element. True enables an instance of the element to have the null attribute set to true. The null attribute is defined as part of the XML Schema namespace for instances. Default is false
57 |
# File 'lib/xsd/objects/element.rb', line 57 property :nillable, :boolean, default: false |
#substitution_group ⇒ Object
Optional. Specifies the name of an element that can be substituted with this element. This attribute cannot be used if the parent element is not the schema element
30 |
# File 'lib/xsd/objects/element.rb', line 30 property :substitutionGroup, :string |
#type ⇒ Object
Optional. Specifies either the name of a built-in data type, or the name of a simpleType or complexType element
24 |
# File 'lib/xsd/objects/element.rb', line 24 property :type, :string |
#unique ⇒ Object
Nested unique objects
89 |
# File 'lib/xsd/objects/element.rb', line 89 child :unique, [:unique] |
Instance Method Details
#attributes? ⇒ Boolean
Determine if element has attributes
123 124 125 |
# File 'lib/xsd/objects/element.rb', line 123 def attributes? complex_type && collect_attributes.any? end |
#complex_content? ⇒ Boolean
Determine if element has complex content
105 106 107 108 |
# File 'lib/xsd/objects/element.rb', line 105 def complex_content? # this is not an opposite to simple_content?, element may have neither complex_type&.complex_content? || false end |
#data_type ⇒ Object
Get base data type
159 160 161 162 163 164 165 166 167 |
# File 'lib/xsd/objects/element.rb', line 159 def data_type if complex_type complex_type.data_type elsif simple_type simple_type.data_type else strip_prefix(type) end end |
#global? ⇒ Boolean
Check is this attribute is global (immediate child of schema element)
153 154 155 |
# File 'lib/xsd/objects/element.rb', line 153 def global? parent.is_a?(Schema) end |
#mixed_content? ⇒ Boolean
Determine if element has mixed content
129 130 131 |
# File 'lib/xsd/objects/element.rb', line 129 def mixed_content? complex_type&.mixed_content? || false end |
#optional? ⇒ Boolean
Determine if element is optional
99 100 101 |
# File 'lib/xsd/objects/element.rb', line 99 def optional? !required? end |
#required? ⇒ Boolean
Determine if element is required
93 94 95 |
# File 'lib/xsd/objects/element.rb', line 93 def required? computed_min_occurs > 0 end |
#simple_content? ⇒ Boolean
Determine if element has simple content
112 113 114 115 116 117 118 119 |
# File 'lib/xsd/objects/element.rb', line 112 def simple_content? # this is not an opposite to complex_content?, element may have neither if complex_type complex_type.simple_content? else true end end |
#substitutable_elements ⇒ Object
Get substitutable elements
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/xsd/objects/element.rb', line 135 def substitutable_elements @substitutable_elements ||= begin if ref reference.substitutable_elements elsif !global? || %w[#all substitution].include?(block) [] else # TODO: we search substituted element only in the same schema with head element, is this enough? # TODO: maybe don't collect all elements but search with xpath first? schema.collect_elements.select do |element| strip_prefix(element.substitution_group) == name end end end end |