Class: XMLBuilder::PathParser::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/ec2/amitools/xmlbuilder.rb

Overview

Node classes Each class represents a node type. An array of these classes is built up when the path is parsed. Each node is then visited by the current rexml node and (depending on which visit function is called) the action taken.

The visit function are:

- walk: Walks down the xml dom
- assign: Assigns the value to rexml node
- retrieve: Retrives the value of the rexml node

Different node types implement different behaviour types. For example retrieve is 
illegal on Attribute nodes, but on Document and Attribute nodes the given node is returned.

Instance Method Summary collapse

Constructor Details

#initializeDocument

Returns a new instance of Document.



132
133
# File 'lib/ec2/amitools/xmlbuilder.rb', line 132

def initialize()
end

Instance Method Details

#assign_visit(document_node, value) ⇒ Object



142
143
144
145
146
147
148
149
150
# File 'lib/ec2/amitools/xmlbuilder.rb', line 142

def assign_visit(document_node, value)
  raise 'Can only assign REXML::Elements to document nodes' if !value.is_a?(REXML::Element)
  raise 'Expected a document node' if !document_node.is_a?(REXML::Element)
  if doc.root
    doc.replace_child(doc.root, value)
  else
    doc.add_element(element)
  end
end

#retrieve_visit(document_node) ⇒ Object



152
153
154
# File 'lib/ec2/amitools/xmlbuilder.rb', line 152

def retrieve_visit(document_node)
  document_node
end

#walk_visit(rexml_node) ⇒ Object

Move to the document node (top of the xml dom)



136
137
138
139
140
# File 'lib/ec2/amitools/xmlbuilder.rb', line 136

def walk_visit(rexml_node)
  return rexml_node if rexml_node.is_a?(REXML::Document)
  raise "No document set on node. #{rexml_node.name}" if rexml_node.document == nil
  rexml_node.document
end