class Saxerator::Builder::XmlBuilder

Attributes

name[R]

Public Class Methods

new(config, name, attributes) click to toggle source
# File lib/saxerator/builder/xml_builder.rb, line 8
def initialize(config, name, attributes)
  @config = config
  @name = name
  @attributes = attributes
  @children = []
  @text = false
end

Public Instance Methods

add_node(node) click to toggle source
# File lib/saxerator/builder/xml_builder.rb, line 16
def add_node(node)
  @text = true if node.is_a? String
  @children << node
end
block_variable() click to toggle source
# File lib/saxerator/builder/xml_builder.rb, line 32
def block_variable
  builder = REXML::Document.new
  builder << REXML::XMLDecl.new('1.0', 'UTF-8')
  to_xml(builder)
  builder
end
to_xml(builder) click to toggle source
# File lib/saxerator/builder/xml_builder.rb, line 21
def to_xml(builder)
  element = REXML::Element.new(name, nil, attribute_quote: :quote)
  element.add_attributes(@attributes)
  if @text
    element.add_text(@children.join)
  else
    @children.each { |child| child.to_xml(element) }
  end
  builder.elements << element
end