I am encountering problems writing XML files using PHP. The following is my php script to write content into an xml file. Basically, no errors have been encountered; but when I check my xml file after running the script, it is empty. Please advice. Thank you.
$doc= new DOMDocument();
$doc->load("articles.xml");
$b = $doc->createElement( "articleDraft" );
$id = $doc->createElement("id");
$id->appendChild(
$doc->createTextNode( $_POST['id'] ) );
$b->appendChild( $id );
$draft=$doc->createElement("draftContent");
$draft->appendChild($doc->createTextNode($_POST['articleBody']));
$b->appendChild($draft);
$time=$doc->createElement("drafTime");
$draft->appendChild($doc->createTextNode(time()));
$b->appendChild($time);
$doc->save("articles.xml");
I am new to writing xml in PHP, please help me identify other problems if you find any. Thank you.