使用domdocument在两个XML元素内部编写

So I'm creating a register script with XML. You can log in fine but I am having trouble with the registering part. Here is my attempt at registration:

<?
    session_start();
    $w = new DOMDocument();
    $w->formatOutput = true;
    $r = $w->createElement("accounts");
    $w->appendChild($r);
    $b = $w->createElement("account");
    $username = $w->createElement("username");
    $username-> /* ??? */

    $password = $w->createElement("password");
    $password-> /* ??? */   

    // ...
?>

and here is the XML dummy that I want to create:

<accounts>
    <account>
        <username>foo</username>
        <password>foo</password>
        <email>foo</email>
        <ip>foo</ip>
        <balance>700</balance>
    </account>
</accounts>

http://php.net/manual/en/domdocument.createelement.php

$w->createElement('username','foo');