1 require "rexml/parseexception"
2 require "rexml/formatters/pretty"
3 require "rexml/formatters/default"
6 # Represents a node in the tree. Nodes are never encountered except as
7 # superclasses of other objects. Nodes have siblings.
9 # @return the next sibling (nil if unset)
11 return nil if @parent.nil?
12 @parent[ @parent.index(self) + 1 ]
15 # @return the previous sibling (nil if unset)
16 def previous_sibling_node
17 return nil if @parent.nil?
18 ind = @parent.index(self)
19 return nil if ind == 0
24 # *DEPRECATED* This parameter is now ignored. See the formatters in the
25 # REXML::Formatters package for changing the output style.
28 Kernel.warn( "#{self.class.name}.to_s(indent) parameter is deprecated" )
29 f = REXML::Formatters::Pretty.new( indent )
30 f.write( self, rv = "" )
32 f = REXML::Formatters::Default.new
33 f.write( self, rv = "" )
39 if @parent and @parent.context and not @parent.context[:indentstyle].nil? then
40 indentstyle = @parent.context[:indentstyle]
44 to << indentstyle*ind unless ind<1
52 # Visit all subnodes of +self+ recursively
53 def each_recursive(&block) # :yields: node
54 self.elements.each {|node|
56 node.each_recursive(&block)
60 # Find (and return) first subnode (recursively) for which the block
61 # evaluates to true. Returns +nil+ if none was found.
62 def find_first_recursive(&block) # :yields: node
63 each_recursive {|node|
64 return node if block.call(node)
69 # Returns the position that +self+ holds in its parent's array, indexed