convert nested arrays into DOMDocument with minimum CPU and time consumption