1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
$this->getResponse()->clearHeaders();
$this->getResponse()->setHeader('Content-Type', 'text/xml');
// Instance de la class DomDocument
$doc = new DOMDocument();
// Definition de la version et l'encodage
$doc->version = '1.0';
$doc->encoding = 'utf-8';
// Ajout d'un commentaire a la racine
$comment_elt = $doc->createComment('Créé par Prénom NOM (email)');
$doc->appendChild($comment_elt);
// Ajout la balise 'note' a la racine
$note_elt = $doc->createElement('note');
$doc->appendChild($note_elt);
// Creation des elements 'to' 'from' 'heading' 'body'
$to_elt = $doc->createElement('to', 'Nicolas');
$from_elt = $doc->createElement('from', 'Carla');
$heading_elt = $doc->createElement('heading', 'Rappel');
// Pas de contenu pour l'instant pour cet element car on desir y mettre une balise CDATA
$body_elt = $doc->createElement('body');
// Specifier que les elements to/from/heading/body sont dans 'note'
$note_elt->appendChild($to_elt);
$note_elt->appendChild($from_elt);
$note_elt->appendChild($heading_elt);
$note_elt->appendChild($body_elt);
// Creation d'une section CDATA
$body_cdata_elt = $doc->createCDATASection("N'oublie pas tes talonnettes");
// Placement de cette section entre les balises <body> et </body>
$body_elt->appendChild($body_cdata_elt);
// Rendre Joli ;)
$doc->formatOutput = true;
// Afficher le document XML
$this->view->xml = $doc->saveXML(); |
Partager