Class: Shale::Schema::XMLGenerator::Element Private

Inherits:
Object
  • Object
show all
Defined in:
lib/shale/schema/xml_generator/element.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> element. Serves as a base class for TypedElement and RefElement

Direct Known Subclasses

RefElement, TypedElement

Instance Method Summary collapse

Constructor Details

#initialize(default, collection, required) ⇒ Element

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 Element object

Parameters:

  • default (String, nil)
  • collection (true, false)
  • required (true, false)


18
19
20
21
22
# File 'lib/shale/schema/xml_generator/element.rb', line 18

def initialize(default, collection, required)
  @default = default
  @collection = collection
  @required = required
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:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/shale/schema/xml_generator/element.rb', line 31

def as_xml(doc)
  element = doc.create_element('xs:element')

  attributes.each do |name, value|
    doc.add_attribute(element, name, value)
  end

  unless @required
    doc.add_attribute(element, 'minOccurs', 0)
  end

  if @collection
    doc.add_attribute(element, 'maxOccurs', 'unbounded')
  end

  unless @default.nil?
    doc.add_attribute(element, 'default', @default)
  end

  element
end