Class REXML::Light::Node
In:
Parent: Object

Represents a tagged XML element. Elements are characterized by having children, attributes, and names, and can themselves be children.

Methods

<<   =~   []   []=   children   each   has_name?   local_name   local_name=   name   name=   namespace   namespace=   new   node_type   parent   parent=   prefix   root   size   text=   to_s  

Constants

NAMESPLIT = /^(?:(#{XMLTokens::NCNAME_STR}):)?(#{XMLTokens::NCNAME_STR})/u
PARENTS = [ :element, :document, :doctype ]

Public Class methods

Create a new element.

[Source]

21:                         def initialize node=nil
22:                                 @node = node
23:                                 if node.kind_of? String
24:                                         node = [ :text, node ]
25:                                 elsif node.nil?
26:                                         node = [ :document, nil, nil ]
27:                                 elsif node[0] == :start_element
28:                                         node[0] = :element
29:                                 elsif node[0] == :start_doctype
30:                                         node[0] = :doctype
31:                                 elsif node[0] == :start_document
32:                                         node[0] = :document
33:                                 end
34:                         end

Public Instance methods

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.

[Source]

122:                         def << element
123:                                 if node_type() == :text
124:                                         at(-1) << element
125:                                 else
126:                                         newnode = Node.new( element )
127:                                         newnode.parent = self
128:                                         self.push( newnode )
129:                                 end
130:                                 at(-1)
131:                         end

[Source]

 98:                         def =~( path )
 99:                                 XPath.match( self, path )
100:                         end

[Source]

86:                         def []( reference, ns=nil )
87:                                 if reference.kind_of? String
88:                                         pfx = ''
89:                                         pfx = "#{prefix(ns)}:" if ns
90:                                         at(3)["#{pfx}#{reference}"]
91:                                 elsif reference.kind_of? Range
92:                                         _old_get( Range.new(4+reference.begin, reference.end, reference.exclude_end?) )
93:                                 else
94:                                         _old_get( 4+reference )
95:                                 end
96:                         end

Doesn‘t handle namespaces yet

[Source]

103:                         def []=( reference, ns, value=nil )
104:                                 if reference.kind_of? String
105:                                         value = ns unless value
106:                                         at( 3 )[reference] = value
107:                                 elsif reference.kind_of? Range
108:                                         _old_put( Range.new(3+reference.begin, reference.end, reference.exclude_end?), ns )
109:                                 else
110:                                         if value
111:                                                 _old_put( 4+reference, ns, value )
112:                                         else
113:                                                 _old_put( 4+reference, ns )
114:                                         end
115:                                 end
116:                         end

[Source]

151:                         def children
152:                                 self
153:                         end

[Source]

44:                         def each( &block )
45:                                 size.times { |x| yield( at(x+4) ) }
46:                         end

[Source]

147:                         def has_name?( name, namespace = '' )
148:                                 at(3) == name and namespace() == namespace
149:                         end

[Source]

62:                         def local_name
63:                                 namesplit
64:                                 @name
65:                         end

[Source]

67:                         def local_name=( name_str )
68:                                 _old_put( 1, "#@prefix:#{name_str}" )
69:                         end

[Source]

48:                         def name
49:                                 at(2)
50:                         end

[Source]

52:                         def name=( name_str, ns=nil )
53:                                 pfx = ''
54:                                 pfx = "#{prefix(ns)}:" if ns
55:                                 _old_put(2, "#{pfx}#{name_str}")
56:                         end

[Source]

75:                         def namespace( prefix=prefix() )
76:                                 namespace_of( self, prefix )
77:                         end

[Source]

79:                         def namespace=( namespace )
80:                                 @prefix = prefix( namespace )
81:                                 pfx = ''
82:                                 pfx = "#@prefix:" if @prefix.size > 0
83:                                 _old_put(1, "#{pfx}#@name")
84:                         end

[Source]

133:                         def node_type
134:                                 _old_get(0)
135:                         end

[Source]

155:                         def parent
156:                                 at(1)
157:                         end

[Source]

58:                         def parent=( node )
59:                                 _old_put(1,node)
60:                         end

[Source]

71:                         def prefix( namespace=nil )
72:                                 prefix_of( self, namespace )
73:                         end

[Source]

142:                         def root
143:                                 context = self
144:                                 context = context.at(1) while context.at(1)
145:                         end

[Source]

36:                         def size
37:                                 if PARENTS.include? @node[0]
38:                                         @node[-1].size
39:                                 else
40:                                         0
41:                                 end
42:                         end

[Source]

137:                         def text=( foo )
138:                                 replace = at(4).kind_of?(String)? 1 : 0
139:                                 self._old_put(4,replace, normalizefoo)
140:                         end

[Source]

159:                         def to_s
160: 
161:                         end

Search

Google

Ruby API Docs

Links