Go to google maps and some special characters ë è & ä etc.'; $string = htmlentities($string, ENT_QUOTES, 'UTF-8'); $doc = new DOMDocument('1.0', 'UTF-8'); $doc->preserveWhiteSpace = false; $doc->formatOutput = true; $root = $doc->createElement('top'); $root = $doc->appendChild($root); $title = $doc->createElement('title', $string); $title = $root->appendChild($title); $id = $doc->createAttribute('id'); $id->value = '1'; $text = $title->appendChild($id); $text = $title->appendChild($text); $doc->save('data.xml'); echo 'data saved!'; ?>