The XML parser converts the text of an XML document into UTF-8, even if you have set the character encoding of the XML, for example as a second parameter of the DOMDocument constructor. After parsing the XML with the load() command all its texts have been converted to UTF-8.
In case you append text nodes with special characters (e. g. Umlaut) to your XML document you should therefore use utf8_encode() with your text to convert it into UTF-8 before you append the text to the document. Otherwise you will get an error message like "output conversion failed due to conv error" at the save() command. See example below:
<?php
$txt = "a text with special characters like 'ä', 'ß', 'Ü' etc.";
$dom = new DOMDocument;
$dom = $dom->load("file.xml");
$parent = $dom->documentElement;
$xpath = new DomXPath($dom);
$next = $xpath->query("//parentnode/childnode");
$new_elem = $dom->createElement('new_elem');
$parent->insertBefore($new_elem, $next->item(0));
$txt = utf8_encode($txt);
$nodetext = $dom->createTextNode("$txt");
$nodetext = $new_elem->appendChild($nodetext);
$dom->save("file.xml");
?>
Hope this helps someone.
siegparr