method
add
v1_8_7_330 -
Show latest stable
- Class:
REXML::Document
add( child )public
We override this, because XMLDecls and DocTypes must go at the start of the document
# File lib/rexml/document.rb, line 67
def add( child )
if child.kind_of? XMLDecl
@children.unshift child
child.parent = self
elsif child.kind_of? DocType
# Find first Element or DocType node and insert the decl right
# before it. If there is no such node, just insert the child at the
# end. If there is a child and it is an DocType, then replace it.
insert_before_index = 0
@children.find { |x|
insert_before_index += 1
x.kind_of?(Element) || x.kind_of?(DocType)
}
if @children[ insert_before_index ] # Not null = not end of list
if @children[ insert_before_index ].kind_of DocType
@children[ insert_before_index ] = child
else
@children[ index_before_index-1, 0 ] = child
end
else # Insert at end of list
@children[insert_before_index] = child
end
child.parent = self
else
rv = super
raise "attempted adding second root element to document" if @elements.size > 1
rv
end
end Related methods
- Instance methods
- <<
- add
- add_element
- clone
- doctype
- encoding
- expanded_name
- name
- node_type
- record_entity_expansion
- root
- stand_alone?
- version
- write
- xml_decl
- Class methods
- entity_expansion_limit
- entity_expansion_limit=
- new
- parse_stream
- Private methods
-
build