php domを使用して、xmlファイルが存在するかどうかを確認し、存在しない場合は作成するにはどうすればよいですか。
<?php
header("Location: index.php");
$xmldoc = new DOMDocument();
$xmldoc->load('sample.xml');
$newAct = $_POST['activity'];
$root = $xmldoc->firstChild;
$newElement = $xmldoc->createElement('activity');
$root->appendChild($newElement);
$newText = $xmldoc->createTextNode($newAct);
$newElement->appendChild($newText);
$xmldoc->save('sample.xml');
?>
現在、存在しないため、次のエラーが発生します。
DOMDocument::load(): I/O warning : failed to load external entity