XML; $xml = new SimpleXMLElement($note); $xml->addAttribute("type","private"); $xml->body->addAttribute("date","2013-01-01"); echo $xml->asXML();