<!DOCTYPE html>
<html>
<body>

<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;

$xml=new SimpleXMLElement($note);
$xml->addAttribute("type","private");
$xml->body->addAttribute("date","2014-01-01");

echo $xml->asXML();
?>


<p>Select View Source to see the added "type" attribute (added to the note element), and the "date" attribute (added to the body element).</p>

</body>
</html>