Class: XmlVisitor

Inherits:
NodeVisitor show all
Defined in:
lib/xml_command_handlers/models/xml_visitor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeXmlVisitor

Returns a new instance of XmlVisitor.



7
8
9
# File 'lib/xml_command_handlers/models/xml_visitor.rb', line 7

def initialize
  @document = ""
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



5
6
7
# File 'lib/xml_command_handlers/models/xml_visitor.rb', line 5

def document
  @document
end

Instance Method Details

#append_attributes(node) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/xml_command_handlers/models/xml_visitor.rb', line 49

def append_attributes(node)
  Glimmer.logger.debug "Take 3"
  Glimmer.logger.debug(node.attributes)
  node.attributes.each_key do |attribute|
    attribute_name = attribute
    attribute_name = "#{attribute.name_space.name}:#{attribute.name}" if attribute.is_a?(Node)
    @document << " #{attribute_name}=\"#{node.attributes[attribute]}\""
  end
end

#append_close_tag(node) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/xml_command_handlers/models/xml_visitor.rb', line 41

def append_close_tag(node)
  if (node.contents)
    @document << "</"
    @document << "#{node.name_space.name}:" if node.name_space
    @document << "#{node.name}>"
  end
end

#begin_open_tag(node) ⇒ Object



26
27
28
29
30
# File 'lib/xml_command_handlers/models/xml_visitor.rb', line 26

def begin_open_tag(node)
  @document << "<"
  @document << "#{node.name_space.name}:" if node.name_space
  @document << node.name
end

#end_open_tag(node) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/xml_command_handlers/models/xml_visitor.rb', line 32

def end_open_tag(node)
  if (node.contents)
    @document << ">"
  else
    @document << " " if node.attributes.keys.size > 0
    @document << "/>"
  end
end

#process_after_children(node) ⇒ Object



21
22
23
24
# File 'lib/xml_command_handlers/models/xml_visitor.rb', line 21

def process_after_children(node)
  return if (node.is_a?(String))
  append_close_tag(node)
end

#process_before_children(node) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/xml_command_handlers/models/xml_visitor.rb', line 11

def process_before_children(node)
  if (node.is_a?(String))
    @document << node
    return
  end
  begin_open_tag(node)
  append_attributes(node) if node.attributes
  end_open_tag(node)
end