Some advices for common programmers problems

Let’s go

$xml = new DOMDocument('1.0', 'UTF-8');
$xml->preserveWhiteSpace = FALSE;
$xml->formatOutput = TRUE;
$xml->appendChild(new DOMElement('items'));

// access to root element without checking if exists !
$root = $xml->documentElement;

// create new node called item and put it to root (items)
$item = $root->appendChild($xml->createElement('item'));

// create custom node in item child called key with value called Test
$item->appendChild($xml->createElement('key'))->
appendChild($xml->createTextNode('Test'));

$xml->save('test.xml');