How to insert node in hierarchy of DOM between one node and it's child nodes?
===

I have a DOM looking like this:

     div id = main
       div
       div

And i want to put the div called "middle" like this:

      div id = main
       div id = middle
         div
         div

So i want to move all child nodes of main node to the middle node and the middle node to become only child of main. I try to figure it out but i can't. 

How to do this in PHP?

