Class: XSD::ComplexType

Inherits:
BaseObject show all
Includes:
AttributeContainer, Named
Defined in:
lib/xsd/objects/complex_type.rb

Overview

The complexType element defines a complex type. A complex type element is an XML element that contains other elements and/or attributes. Parent elements: element, redefine, schema www.w3schools.com/xml/el_complextype.asp

Constant Summary

Constants inherited from BaseObject

BaseObject::NO_ATTRIBUTES_CONTAINER, BaseObject::NO_ELEMENTS_CONTAINER, BaseObject::XML_SCHEMA

Instance Attribute Summary collapse

Attributes included from AttributeContainer

#attribute_groups, #attributes

Attributes inherited from BaseObject

#id, #options

Instance Method Summary collapse

Methods included from Named

#absolute_name, #namespace

Methods included from AttributeContainer

included

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

#abstractObject

Optional. Specifies whether the complex type can be used in an instance document. True indicates that an element cannot use this complex type directly but must use a complex type derived from this complex type. Default is false

Returns:

  • Boolean



21
# File 'lib/xsd/objects/complex_type.rb', line 21

property :abstract, :boolean, default: false

#allObject

Nested all

Returns:

  • All



65
# File 'lib/xsd/objects/complex_type.rb', line 65

child :all, :all

#blockObject

Optional. Prevents a complex type that has a specified type of derivation from being used in place of this complex type. This value can contain #all or a list that is a subset of extension or restriction:

extension - prevents complex types derived by extension
restriction - prevents complex types derived by restriction
#all - prevents all derived complex types

Returns:

  • String, nil



36
# File 'lib/xsd/objects/complex_type.rb', line 36

property :block, :string

#choiceObject

Nested choice

Returns:

  • Choice



70
# File 'lib/xsd/objects/complex_type.rb', line 70

child :choice, :choice

#complex_contentObject

Complex content object

Returns:

  • ComplexContent



55
# File 'lib/xsd/objects/complex_type.rb', line 55

child :complex_content, :complexContent

#finalObject

Optional. Prevents a specified type of derivation of this complex type element. Can contain #all or a list that is a subset of extension or restriction.

extension - prevents derivation by extension
restriction - prevents derivation by restriction
#all - prevents all derivation

Returns:

  • String, nil



45
# File 'lib/xsd/objects/complex_type.rb', line 45

property :final, :string

#groupObject

Nested group

Returns:

  • Group



60
# File 'lib/xsd/objects/complex_type.rb', line 60

child :group, :group

#mixedObject

Optional. Specifies whether character data is allowed to appear between the child elements of this complexType element. Default is false. If a simpleContent element is a child element, the mixed attribute is not allowed!

Returns:

  • Boolean



27
# File 'lib/xsd/objects/complex_type.rb', line 27

property :mixed, :boolean, default: false

#nameObject

Optional. Specifies a name for the element

Returns:

  • String



15
# File 'lib/xsd/objects/complex_type.rb', line 15

property :name, :string

#sequenceObject

Nested sequence

Returns:

  • Sequence



75
# File 'lib/xsd/objects/complex_type.rb', line 75

child :sequence, :sequence

#simple_contentObject

Simple content object

Returns:

  • SimpleContent



50
# File 'lib/xsd/objects/complex_type.rb', line 50

child :simple_content, :simpleContent

Instance Method Details

#complex_content?Boolean

Determine if this type has complex content definition

Returns:

  • (Boolean)

    Boolean



99
100
101
102
103
104
105
106
107
# File 'lib/xsd/objects/complex_type.rb', line 99

def complex_content?
  if simple_content
    false
  elsif complex_content
    true
  else
    group || all || choice || sequence
  end
end

#data_typeObject

Get simple content data type

Returns:

  • String, nil



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/xsd/objects/complex_type.rb', line 117

def data_type
  return nil unless simple_content

  restriction = simple_content.restriction
  if restriction
    if restriction.base
      if restriction.base_simple_type
        restriction.base_simple_type.data_type
      elsif restriction.base_complex_type
        restriction.base_complex_type.data_type
      else
        strip_prefix(restriction.base)
      end
    else
      restriction.simple_type&.data_type
    end
  else
    extension = simple_content.extension
    if extension.base_simple_type
      extension.base_simple_type.data_type
    elsif extension.base_complex_type
      extension.base_complex_type.data_type
    else
      strip_prefix(extension.base)
    end
  end
end

#linked?Boolean

Determine if this is a linked type

Returns:

  • (Boolean)

    Boolean



79
80
81
# File 'lib/xsd/objects/complex_type.rb', line 79

def linked?
  !name.nil?
end

#mixed_content?Boolean

Determine if this type has mixed content definition

Returns:

  • (Boolean)

    Boolean



85
86
87
88
89
90
91
92
93
94
95
# File 'lib/xsd/objects/complex_type.rb', line 85

def mixed_content?
  return true if mixed

  if complex_content
    return true if complex_content.mixed

    return (complex_content.extension || complex_content.restriction).base_complex_type&.mixed_content?
  end

  false
end

#simple_content?Boolean

Determine if this type has simple content definition

Returns:

  • (Boolean)

    Boolean



111
112
113
# File 'lib/xsd/objects/complex_type.rb', line 111

def simple_content?
  !!simple_content
end