Class: HTML5::TreeBuilders::REXML::Element

Inherits:
Node show all
Defined in:
lib/html5/treebuilders/rexml.rb

Direct Known Subclasses

DocumentFragment

Instance Attribute Summary collapse

Attributes inherited from Node

#rxobj

Attributes inherited from Base::Node

#childNodes, #flags, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#appendChild, #hasContent, #insertBefore, #insertText, #removeChild

Methods inherited from Base::Node

#appendChild, #hasContent, #insertBefore, #insertText, #removeChild, #reparentChildren

Constructor Details

#initialize(name, namespace = nil) ⇒ Element

Returns a new instance of Element.



66
67
68
69
# File 'lib/html5/treebuilders/rexml.rb', line 66

def initialize name, namespace=nil
  super name
  @namespace = namespace
end

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace.



61
62
63
# File 'lib/html5/treebuilders/rexml.rb', line 61

def namespace
  @namespace
end

Class Method Details

.rxclassObject



62
63
64
# File 'lib/html5/treebuilders/rexml.rb', line 62

def self.rxclass
  ::REXML::Element
end

Instance Method Details

#attributes=(value) ⇒ Object



77
78
79
# File 'lib/html5/treebuilders/rexml.rb', line 77

def attributes= value
  value.each {|name, v| rxobj.attributes[name] = v}
end

#cloneNodeObject



71
72
73
74
75
# File 'lib/html5/treebuilders/rexml.rb', line 71

def cloneNode
  newNode = self.class.new name
  attributes.each {|name,value| newNode.attributes[name] = value}
  newNode
end

#printTree(indent = 0) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/html5/treebuilders/rexml.rb', line 81

def printTree indent=0
  tree = "\n|#{' ' * indent}<#{namespace ? namespace.to_s + ' ' : ''}#{name}>"
  indent += 2
  for name, value in attributes
    next if name == 'xmlns'
    tree += "\n|#{' ' * indent}#{name}=\"#{value}\""
  end
  for child in childNodes
    tree += child.printTree(indent)
  end
  tree
end