在运行脚本后,使用PHP编写XML没有任何影响

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.

You simply forgot:

$doc->appendChild($b);

Edit: If you want to format your output, add:

$doc->formatOutput = true;

Otherwise your output is not human-friendly.

$doc->appendChild($b); before save