有一个XML文件,内容如下:
复制代码 代码如下:
<"1.0""codetitle">复制代码 代码如下:
$indexUrl='http://www.xxx.com/xxx.xml';
$reader = new XMLReader();
$reader->open($indexUrl);
$countElements = 0;
while ($reader->read()){
if($reader->nodeType == XMLReader::ELEMENT){
$nodeName = $reader->name;
}
if($reader->nodeType == XMLReader::TEXT && !empty($nodeName)){
switch($nodeName){
case 'name':
$name = $reader->value;
break;
case 'channel':
$channel = $reader->value;
break;
case 'start':
$start = $reader->value;
break;
case 'duration':
$duration = $reader->value;
break;
}
}
}
$reader->close();