class Nokogiri::XML::Node

def add_next_sibling node_or_tags

Also see related method +after+.

Returns the reparented node (if +node_or_tags+ is a Node), or NodeSet (if +node_or_tags+ is a DocumentFragment, NodeSet, or string).

+node_or_tags+ can be a Nokogiri::XML::Node, a ::DocumentFragment, a ::NodeSet, or a string containing markup.
Insert +node_or_tags+ after this Node (as a sibling).
##
def add_next_sibling node_or_tags
  raise ArgumentError.new("A document may not have multiple root nodes.") if parent.is_a?(XML::Document)
  
  node_or_tags = coerce(node_or_tags)
  if node_or_tags.is_a?(XML::NodeSet)
    if text?
      pivot = Nokogiri::XML::Node.new 'dummy', document
      add_next_sibling_node pivot
    else
      pivot = self
    end
    node_or_tags.reverse_each { |n| pivot.send :add_next_sibling_node, n }
    pivot.unlink if text?
  else
    add_next_sibling_node node_or_tags
  end
  node_or_tags
end