Class: REXML::Element

Inherits:
Object show all
Defined in:
lib/agent_xmpp/patches/rexml.rb

Overview


Direct Known Subclasses

AgentXmpp::Xmpp::Element

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) import(xmlelement)

.......................................................................................................



55
56
57
# File 'lib/agent_xmpp/patches/rexml.rb', line 55

def self.import(xmlelement)
  self.new(xmlelement.name).import(xmlelement)
end

Instance Method Details

- (Object) delete_elements(element)

.......................................................................................................



60
61
62
# File 'lib/agent_xmpp/patches/rexml.rb', line 60

def delete_elements(element)
  elements.delete_all(element)
end

- (Object) first_element(e)

.......................................................................................................



20
21
22
# File 'lib/agent_xmpp/patches/rexml.rb', line 20

def first_element(e)
  elements.to_a(e).first
end

- (Object) first_element_text(e)

.......................................................................................................



25
26
27
28
# File 'lib/agent_xmpp/patches/rexml.rb', line 25

def first_element_text(e)
  el = first_element(e)
  el.nil? ? nil : el.text
end

- (Object) import(xmlelement)

.......................................................................................................



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/agent_xmpp/patches/rexml.rb', line 36

def import(xmlelement)
  if @name and @name != xmlelement.name
    raise "Trying to import an #{xmlelement.name} to a #{@name} !"
  end
  add_attributes(xmlelement.attributes.clone)
  @context = xmlelement.context
  xmlelement.each do |e|
    if e.kind_of? REXML::Element
      typed_add(e.deep_clone)
    elsif e.kind_of? REXML::Text
      add_text(e.value)
    else
      add(e.clone)
    end
  end
  self
end

- (Object) replace_element_text(e, t)

.......................................................................................................



9
10
11
12
13
14
15
16
17
# File 'lib/agent_xmpp/patches/rexml.rb', line 9

def replace_element_text(e, t)
  el = first_element(e)
  if el.nil?
    el = REXML::Element.new(e)
    add_element(el)
  end
  el.text = t if t
  self
end

- (Object) typed_add(e)

.......................................................................................................



31
32
33
# File 'lib/agent_xmpp/patches/rexml.rb', line 31

def typed_add(e)
  add(e)
end