add( child )
public
We override this, because XMLDecls and DocTypes must go at the start of the
document
Show source
def add( child )
if child.kind_of? XMLDecl
if @children[0].kind_of? XMLDecl
@children[0] = child
else
@children.unshift child
end
child.parent = self
elsif child.kind_of? DocType
insert_before_index = @children.find_index { |x|
x.kind_of?(Element) || x.kind_of?(DocType)
}
if insert_before_index
if @children[ insert_before_index ].kind_of? DocType
@children[ insert_before_index ] = child
else
@children[ insert_before_index-1, 0 ] = child
end
else
@children << child
end
child.parent = self
else
rv = super
raise "attempted adding second root element to document" if @elements.size > 1
rv
end
end