class XMLBuilder

Attributes

root[R]

Public Class Methods

new(root = nil) click to toggle source

Create a new XMLBuilder rooted at the given element, or at a new document if no root is given

# File lib/ec2/amitools/xmlbuilder.rb, line 45
def initialize(root = nil)
  @root = root || REXML::Document.new()
end

Public Instance Methods

[](path) click to toggle source

Retrieve a builder for the element at the given path

# File lib/ec2/amitools/xmlbuilder.rb, line 50
def [](path)
  nodes = PathParser.parse(path)
  rexml_node = nodes.inject(@root) do |rexml_node, parser_node|
    parser_node.walk_visit(rexml_node)
  end
  XMLBuilder.new(nodes.last.retrieve_visit(rexml_node))
end
[]=(path, value) click to toggle source

Set the value of the element or attribute at the given path

# File lib/ec2/amitools/xmlbuilder.rb, line 59
def []=(path, value)
  # Don't create elements or make assignments for nil values
  return if value.nil?
  nodes = PathParser.parse(path)
  rexml_node = nodes.inject(@root) do |rexml_node, parser_node|
    parser_node.walk_visit(rexml_node)
  end
  nodes.last.assign_visit(rexml_node, value)
end