Class: REXML::Light::Node
Overview
Represents a tagged XML element. Elements are characterized by having children, attributes, and names, and can themselves be children.
Constant Summary
- NAMESPLIT =
/^(?:(#{XMLTokens::NCNAME_STR}):)?(#{XMLTokens::NCNAME_STR})/u- PARENTS =
[ :element, :document, :doctype ]
Instance Method Summary (collapse)
-
- (Object) <<(element)
Append a child to this element, optionally under a provided namespace.
- - (Object) =~(path)
- - (Object) [](reference, ns = nil)
-
- (Object) []=(reference, ns, value = nil)
Doesn't handle namespaces yet.
- - (Object) children
- - (Object) each(&block)
- - (Boolean) has_name?(name, namespace = '')
-
- (Node) initialize(node = nil)
constructor
Create a new element.
- - (Object) local_name
- - (Object) local_name=(name_str)
- - (Object) name
- - (Object) name=(name_str, ns = nil)
- - (Object) namespace(prefix = prefix())
- - (Object) namespace=(namespace)
- - (Object) node_type
- - (Object) parent
- - (Object) parent=(node)
- - (Object) prefix(namespace = nil)
- - (Object) root
- - (Object) size
- - (Object) text=(foo)
- - (Object) to_s
Constructor Details
- (Node) initialize(node = nil)
Create a new element.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rexml/light/node.rb', line 21 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 Method Details
- (Object) <<(element)
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.
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/rexml/light/node.rb', line 122 def << element if node_type() == :text at(-1) << element else newnode = Node.new( element ) newnode.parent = self self.push( newnode ) end at(-1) end |
- (Object) =~(path)
98 99 100 |
# File 'lib/rexml/light/node.rb', line 98 def =~( path ) XPath.match( self, path ) end |
- (Object) [](reference, ns = nil)
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/rexml/light/node.rb', line 86 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 |
- (Object) []=(reference, ns, value = nil)
Doesn't handle namespaces yet
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/rexml/light/node.rb', line 103 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 |
- (Object) children
151 152 153 |
# File 'lib/rexml/light/node.rb', line 151 def children self end |
- (Object) each(&block)
44 45 46 |
# File 'lib/rexml/light/node.rb', line 44 def each( &block ) size.times { |x| yield( at(x+4) ) } end |
- (Boolean) has_name?(name, namespace = '')
147 148 149 |
# File 'lib/rexml/light/node.rb', line 147 def has_name?( name, namespace = '' ) at(3) == name and namespace() == namespace end |
- (Object) local_name
62 63 64 65 |
# File 'lib/rexml/light/node.rb', line 62 def local_name namesplit @name end |
- (Object) local_name=(name_str)
67 68 69 |
# File 'lib/rexml/light/node.rb', line 67 def local_name=( name_str ) _old_put( 1, "#@prefix:#{name_str}" ) end |
- (Object) name
48 49 50 |
# File 'lib/rexml/light/node.rb', line 48 def name at(2) end |
- (Object) name=(name_str, ns = nil)
52 53 54 55 56 |
# File 'lib/rexml/light/node.rb', line 52 def name=( name_str, ns=nil ) pfx = '' pfx = "#{prefix(ns)}:" if ns _old_put(2, "#{pfx}#{name_str}") end |
- (Object) namespace(prefix = prefix())
75 76 77 |
# File 'lib/rexml/light/node.rb', line 75 def namespace( prefix=prefix() ) namespace_of( self, prefix ) end |
- (Object) namespace=(namespace)
79 80 81 82 83 84 |
# File 'lib/rexml/light/node.rb', line 79 def namespace=( namespace ) @prefix = prefix( namespace ) pfx = '' pfx = "#@prefix:" if @prefix.size > 0 _old_put(1, "#{pfx}#@name") end |
- (Object) node_type
133 134 135 |
# File 'lib/rexml/light/node.rb', line 133 def node_type _old_get(0) end |
- (Object) parent
155 156 157 |
# File 'lib/rexml/light/node.rb', line 155 def parent at(1) end |
- (Object) parent=(node)
58 59 60 |
# File 'lib/rexml/light/node.rb', line 58 def parent=( node ) _old_put(1,node) end |
- (Object) prefix(namespace = nil)
71 72 73 |
# File 'lib/rexml/light/node.rb', line 71 def prefix( namespace=nil ) prefix_of( self, namespace ) end |
- (Object) root
142 143 144 145 |
# File 'lib/rexml/light/node.rb', line 142 def root context = self context = context.at(1) while context.at(1) end |
- (Object) size
36 37 38 39 40 41 42 |
# File 'lib/rexml/light/node.rb', line 36 def size if PARENTS.include? @node[0] @node[-1].size else 0 end end |
- (Object) text=(foo)
137 138 139 140 |
# File 'lib/rexml/light/node.rb', line 137 def text=( foo ) replace = at(4).kind_of?(String)? 1 : 0 self._old_put(4,replace, normalizefoo) end |
- (Object) to_s
159 160 161 |
# File 'lib/rexml/light/node.rb', line 159 def to_s end |