xml をエコーしようとしていますが、xml タグをエコーすることができません。これが私のコードです
<?php
// set feed URL
$feedURL = 'http://gdata.youtube.com/feeds/api/videos?orderby=updated&vq=rihana';
// read feed into SimpleXML object
$sxml = simplexml_load_file($feedURL);
?>
<h1><?php echo $sxml->title; ?></h1>
<?php
$xml = new SimpleXMLElement('<xml></xml>');
// iterate over entries in feed
foreach ($sxml->entry as $entry) {
// get nodes in media: namespace for media information
$media = $entry->children('http://search.yahoo.com/mrss/');
// get video player URL
$attrs = $media->group->player->attributes();
$watch = $attrs['url'];
// get video thumbnail
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail = $attrs['url'];
$track = $xml->addChild('item');
$track->addChild('description', $media->group->description);
$track->addChild('title', $media->group->title);
$track->addChild('url', $watch);
}
?>
<p>
<?php
header('Content-type: text/xml');
echo( htmlentities( $xml->asXML() ) );
foreach ($xml->item as $record) {
echo '<div class="item_record">'."\n";
echo '<h3>'.$record->title.'</h3>'."\n";
echo '<p><span class="category">description: </span>'.$record->description.'</p>'."\n";
echo '<p><span class="category">url: </span><a href='.$record->url.'>'.$record->url.'</a></p>'."\n";
echo '</div>'."\n";
}?>
</p>
私は本当にデータをxml形式で印刷したいのですが、以下のコードからのミックスのようです
echo( htmlentities( $xml->asXML() ) );
そして素敵に見える
foreach ($xml->item as $record) {
echo '<div class="item_record">'."\n";
echo '<h3>'.$record->title.'</h3>'."\n";
echo '<p><span class="category">description: </span>'.$record->description.'</p>'."\n";
echo '<p><span class="category">url: </span><a href='.$record->url.'>'.$record->url.'</a></p>'."\n";
echo '</div>'."\n";
}?>
問題を解決するにはどの操作が最適ですか?