21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
$doc = new DOMDocument('1.0', 'utf-8');
$doc->load('news.xml');
$news = $doc->getElementsByTagName("news");
foreach($news as $elem)
{
$titles = $elem->getElementsByTagName("title");
$title = $titles->item(0)->nodeValue;
$authors = $elem->getElementsByTagName( "author" );
$author = $authors->item(0)->nodeValue;
$dates = $elem->getElementsByTagName( "date" );
$date = $dates->item(0)->nodeValue;
$contents = $elem->getElementsByTagName( "content" );
$content = $contents->item(0)->nodeValue;
$keywordss = $elem->getElementsByTagName( "keywords" );
$keywords = $keywordss->item(0)->nodeValue;
echo "$title - $author - $date - $content - $keywords";
}
?>