Class: REXML::Light::Node
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rexml/light/node.rb |
Overview
Represents a tagged XML element. ::REXML::Elements
are characterized by having children, attributes, and names, and can themselves be children.
Constant Summary
-
NAMESPLIT =
# File 'lib/rexml/light/node.rb', line 10/^(?:(#{XMLTokens::NCNAME_STR}):)?(#{XMLTokens::NCNAME_STR})/u
-
PARENTS =
# File 'lib/rexml/light/node.rb', line 11[ :element, :document, :doctype ]
Class Method Summary
-
.new(node = nil) ⇒ Node
constructor
Create a new element.
Instance Attribute Summary
- #local_name rw
- #local_name=(name_str) rw
- #parent rw
- #parent=(node) rw
- #text=(foo) writeonly
Instance Method Summary
-
#<<(element)
Append a child to this element, optionally under a provided namespace.
- #=~(path)
- #[](reference, ns = nil)
-
#[]=(reference, ns, value = nil)
Doesn’t handle namespaces yet.
- #children
- #each
- #has_name?(name, namespace = '') ⇒ Boolean
- #name
- #name=(name_str, ns = nil)
- #namespace(prefix = prefix())
- #namespace=(namespace)
- #node_type
- #prefix(namespace = nil)
- #root
- #size
- #to_s
- #namespace_of(node, prefix = nil) private
- #namesplit private
- #prefix_of(node, namespace = nil) private
Constructor Details
.new(node = nil) ⇒ Node
Create a new element.
# File 'lib/rexml/light/node.rb', line 13
def initialize node=nil @node = node if node.kind_of? String node = [ :text, node ] elsif node.nil? node = [ :document, nil, nil ] elsif node[0] == :start_element node[0] = :element elsif node[0] == :start_doctype node[0] = :doctype elsif node[0] == :start_document node[0] = :document end end
Instance Attribute Details
#local_name (rw)
[ GitHub ]# File 'lib/rexml/light/node.rb', line 54
def local_name namesplit @name end
#local_name=(name_str) (rw)
[ GitHub ]# File 'lib/rexml/light/node.rb', line 59
def local_name=( name_str ) _old_put( 1, "#@prefix:#{name_str}" ) end
#parent (rw)
[ GitHub ]# File 'lib/rexml/light/node.rb', line 147
def parent at(1) end
#parent=(node) (rw)
[ GitHub ]# File 'lib/rexml/light/node.rb', line 50
def parent=( node ) _old_put(1,node) end
#text=(foo) (writeonly)
[ GitHub ]# File 'lib/rexml/light/node.rb', line 129
def text=( foo ) replace = at(4).kind_of?(String)? 1 : 0 self._old_put(4,replace, normalizefoo) end
Instance Method Details
#<<(element)
Append a child to this element, optionally under a provided namespace. The namespace argument is ignored if the element argument is an ::REXML::Element
object. Otherwise, the element argument is a string, the namespace (if provided) is the namespace the element is created in.
#=~(path)
[ GitHub ]#[](reference, ns = nil)
[ GitHub ]# File 'lib/rexml/light/node.rb', line 78
def []( reference, ns=nil ) if reference.kind_of? String pfx = '' pfx = "#{prefix(ns)}:" if ns at(3)["#{pfx}#{reference}"] elsif reference.kind_of? Range _old_get( Range.new(4+reference.begin, reference.end, reference.exclude_end?) ) else _old_get( 4+reference ) end end
#[]=(reference, ns, value = nil)
Doesn’t handle namespaces yet
# File 'lib/rexml/light/node.rb', line 95
def []=( reference, ns, value=nil ) if reference.kind_of? String value = ns unless value at( 3 )[reference] = value elsif reference.kind_of? Range _old_put( Range.new(3+reference.begin, reference.end, reference.exclude_end?), ns ) else if value _old_put( 4+reference, ns, value ) else _old_put( 4+reference, ns ) end end end
#children
[ GitHub ]# File 'lib/rexml/light/node.rb', line 143
def children self end
#each
[ GitHub ]# File 'lib/rexml/light/node.rb', line 36
def each size.times { |x| yield( at(x+4) ) } end
#has_name?(name, namespace = '') ⇒ Boolean
#name
[ GitHub ]# File 'lib/rexml/light/node.rb', line 40
def name at(2) end
#name=(name_str, ns = nil)
[ GitHub ]# File 'lib/rexml/light/node.rb', line 44
def name=( name_str, ns=nil ) pfx = '' pfx = "#{prefix(ns)}:" if ns _old_put(2, "#{pfx}#{name_str}") end
#namespace(prefix = prefix())
[ GitHub ]# File 'lib/rexml/light/node.rb', line 67
def namespace( prefix=prefix() ) namespace_of( self, prefix ) end
#namespace=(namespace)
[ GitHub ]#namespace_of(node, prefix = nil) (private)
[ GitHub ]#namesplit (private)
[ GitHub ]# File 'lib/rexml/light/node.rb', line 157
def namesplit return if @name.defined? at(2) =~ NAMESPLIT @prefix = '' || $1 @name = $2 end
#node_type
[ GitHub ]# File 'lib/rexml/light/node.rb', line 125
def node_type _old_get(0) end
#prefix(namespace = nil)
[ GitHub ]#prefix_of(node, namespace = nil) (private)
[ GitHub ]#root
[ GitHub ]# File 'lib/rexml/light/node.rb', line 134
def root context = self context = context.at(1) while context.at(1) end
#size
[ GitHub ]# File 'lib/rexml/light/node.rb', line 28
def size if PARENTS.include? @node[0] @node[-1].size else 0 end end
#to_s
[ GitHub ]# File 'lib/rexml/light/node.rb', line 151
def to_s end