Chain nesting XML elements
I don't think you need recursion. Just a simple loop will do. We can just keep a reference to the last element in the document, which we update every time we append a new element, and we keep appending to that.

$tagNames = "this     is a somewhat long string" -split "\s+"
$XML = New-Object System.Xml.XmlDocument

$lastElt = $XML

$tagNames | % { 
    $elt = $XML.CreateElement($_)
    $lastElt = $lastElt.AppendChild($elt)
}

$xml.OuterXml # &lt;this&gt;&lt;is&gt;&lt;a&gt;&lt;somewhat&gt;&lt;long&gt;&lt;string /&gt;&lt;/long&gt;&lt;/somewhat&gt;&lt;/a&gt;&lt;/is&gt;&lt;/this&gt;


I also changed it to split the string on \s+, which is a regular expression meaning "one or whitespace characters", so that multiple consecutive spaces (or tabs or whatever) will be counted as a single thing as far as -split is concerned.

I change $string to $tagNames because it is important to name variables accurately otherwise you will confuse yourself.