Fichiers XML

Afficher du XML

Pour afficher du XML dans un navigateur, il suffit d’ajouter dans les entêtes le type MIME text/xml.

<?php
header('Content-Type: text/xml');
print '<?xml version="1.0"?>' . "\n";
print "<shows>\n";

$shows = array(
  array('name'    => 'Simpsons',
       'channel'  => 'FOX',
       'start'    => '8:00 PM',
       'duration' => '30'),
  array('name'    => 'Law & Order', 
       'channel'  => 'NBC',
       'start'    => '8:00 PM',
       'duration' => '60')
);

foreach ($shows as $show) {
    echo "  <show>\n";
    foreach($show as $tag => $data) {
        echo "    <$tag>" . htmlspecialchars($data) . "</$tag>\n";
    }
    echo "  </show>\n";
}
echo "</shows>\n";

Classes