Object
Represents a tagged XML element. Elements are characterized by having children, attributes, and names, and can themselves be children.
Create a new element.
# File rexml-3.2.5/lib/rexml/light/node.rb, line 12 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
Append a child to this element, optionally under a provided namespace. The namespace argument is ignored if the element argument is an Element object. Otherwise, the element argument is a string, the namespace (if provided) is the namespace the element is created in.
# File rexml-3.2.5/lib/rexml/light/node.rb, line 113 def << element if node_type() == :text at(-1) << element else newnode = Node.new( element ) newnode.parent = self self.push( newnode ) end at(-1) end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 89 def =~( path ) XPath.match( self, path ) end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 77 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
Doesn't handle namespaces yet
# File rexml-3.2.5/lib/rexml/light/node.rb, line 94 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
# File rexml-3.2.5/lib/rexml/light/node.rb, line 142 def children self end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 35 def each size.times { |x| yield( at(x+4) ) } end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 138 def has_name?( name, namespace = '' ) at(3) == name and namespace() == namespace end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 53 def local_name namesplit @name end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 58 def local_name=( name_str ) _old_put( 1, "#@prefix:#{name_str}" ) end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 39 def name at(2) end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 43 def name=( name_str, ns=nil ) pfx = '' pfx = "#{prefix(ns)}:" if ns _old_put(2, "#{pfx}#{name_str}") end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 66 def namespace( prefix=prefix() ) namespace_of( self, prefix ) end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 70 def namespace=( namespace ) @prefix = prefix( namespace ) pfx = '' pfx = "#@prefix:" if @prefix.size > 0 _old_put(1, "#{pfx}#@name") end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 124 def node_type _old_get(0) end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 146 def parent at(1) end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 49 def parent=( node ) _old_put(1,node) end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 62 def prefix( namespace=nil ) prefix_of( self, namespace ) end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 133 def root context = self context = context.at(1) while context.at(1) end
# File rexml-3.2.5/lib/rexml/light/node.rb, line 27 def size if PARENTS.include? @node[0] @node[-1].size else 0 end end