我正在尝试回显 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";
}?>
哪种操作最能解决我的问题?