Class: Shale::Schema::XMLGenerator::ComplexType Private

Inherits:
Object
  • Object
show all
Defined in:
lib/shale/schema/xml_generator/complex_type.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class representing XML Schema element

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, children = [], mixed: false) ⇒ ComplexType

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize ComplexType object

] children

Parameters:



30
31
32
33
34
# File 'lib/shale/schema/xml_generator/complex_type.rb', line 30

def initialize(name, children = [], mixed: false)
  @name = name
  @children = children
  @mixed = mixed
end

Instance Attribute Details

#nameString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return name

Returns:

  • (String)


18
19
20
# File 'lib/shale/schema/xml_generator/complex_type.rb', line 18

def name
  @name
end

Instance Method Details

#as_xml(doc) ⇒ Shale::Adapter::<XML adapter>::Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Append element to the XML document

Parameters:

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/shale/schema/xml_generator/complex_type.rb', line 43

def as_xml(doc)
  complex_type = doc.create_element('xs:complexType')

  doc.add_attribute(complex_type, 'name', @name)
  doc.add_attribute(complex_type, 'mixed', 'true') if @mixed

  elements = @children.select { |e| e.is_a?(Element) }
  attributes = @children.select { |e| e.is_a?(Attribute) }

  unless elements.empty?
    sequence = doc.create_element('xs:sequence')
    doc.add_element(complex_type, sequence)

    elements.each do |element|
      doc.add_element(sequence, element.as_xml(doc))
    end
  end

  attributes.each do |attribute|
    doc.add_element(complex_type, attribute.as_xml(doc))
  end

  complex_type
end