Class: REXML::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/reddy/rexml_hacks.rb

Overview

def subdocument_writer(el)

el.prefixes.each { |ns|
  el.add_attribute('xmlns:' + ns, el.namespaces[ns].to_s)
}
return el.to_s

end

Instance Method Summary collapse

Instance Method Details

#baseString

Tells you what the set xml:lang is for an element.

Returns

Returns:

  • (String)

    The URI of the xml:base.

Author:

  • Tom Morris



58
59
60
61
62
63
64
65
66
# File 'lib/reddy/rexml_hacks.rb', line 58

def base
  if self.attributes['xml:base']
    return self.attributes['xml:base'].to_s
  elsif self.parent != nil
    return self.parent.base
  else
    return nil
  end
end

#base?Boolean

Tells you whether or not an element has a set xml:base.

Returns:

  • (Boolean)

Author:

  • Tom Morris



43
44
45
46
47
48
49
# File 'lib/reddy/rexml_hacks.rb', line 43

def base?
  if self.base != nil
    true
  else
    false
  end
end

#langString

Tells you what the set xml:lang is for an element.

Returns

Returns:

  • (String)

    The URI of the xml:lang.

Author:

  • Tom Morris



29
30
31
32
33
34
35
36
37
# File 'lib/reddy/rexml_hacks.rb', line 29

def lang
  if self.attributes['xml:lang']
    return self.attributes['xml:lang'].to_s
  elsif self.parent != nil
    return self.parent.lang
  else
    return nil
  end
end

#lang?Boolean

Tells you whether or not an element has a set xml:lang.

Returns:

  • (Boolean)

Author:

  • Tom Morris



18
19
20
# File 'lib/reddy/rexml_hacks.rb', line 18

def lang?
  self.lang.nil? ? false : true
end

#write_reddy(excl = []) ⇒ String

Allows you to write out an XML representation of a particular element and it’s children, fixing namespace issues.

Returns

Returns:

  • (String)

    The XML of the element and it’s children.

Author:

  • Tom Morris



75
76
77
78
79
80
81
82
# File 'lib/reddy/rexml_hacks.rb', line 75

def write_reddy(excl=[])
  # TODO: add optional list argument of excluded namespaces
  self.prefixes.each { |ns|
    self.add_attribute('xmlns:' + ns, self.namespaces[ns].to_s) unless excl.include? self.namespaces[ns]
  }
  self.support_write_recursive(self.namespaces, self)
  return self.to_s
end