I think this might help you
//I assume the name of your method is "getStringsNodes()" and it returns the array of strings
$string_array = getStringNodes();
$string_array = array_map('trim', $string_array);
$string_xml = implode('', $string_array);
$new_nodes = new DomDocument();
$new_nodes->loadXML($string_xml);
$first_node = $new_node->getElementsByTagName('math')->item(0);
//I assume the parent XML container is $owner_xml
$owner_xml = new DomDocument();
$owner_xml->loadXML('<sample><parent_node></parent_node></sample>'); //convert this to whatever you need
$node = $owner_xml->importNode($first_node, true);
$parent_node = $owner_xml->getElementsByTagName('parent_node')->item(0);
$parent_node->appendChild($node);
I hope this helps you.