$xml = simplexml_load_file("a.xml");
foreach($xml->file as $sfile)
{
echo $sfile->track . "<br/>";
echo $sfile->caption . "<br/>";
  echo $sfile->record . "<br/>";
}
如果要编码的话,最好用file_get_contents("a.xml");然后转成utf8的,然后用simplexml_load_string()函数

解决方案 »

  1.   


    $str = file_get_contents('a.xml');
    //如果不是utf8的编码
    //$xml = simplexml_load_string(iconv('gb2312', 'utf-8', $str));
    //是utf-8的
    $xml = simplexml_load_string($str);
    foreach($xml->file as $sfile)
    {
    echo $sfile->track . "<br/>";
    echo $sfile->caption . "<br/>";
      echo $sfile->record . "<br/>";
    }
      

  2.   

    出错
    Warning: simplexml_load_file() [function.simplexml-load-file]: a.xml:1: parser warning : xmlParsePITarget: invalid name prefix 'xml' in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: simplexml_load_file() [function.simplexml-load-file]: <?xmlversion="1.0"?> in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: simplexml_load_file() [function.simplexml-load-file]: a.xml:1: parser error : ParsePI: PI xmlversion space expected in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: simplexml_load_file() [function.simplexml-load-file]: <?xmlversion="1.0"?> in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in D:\Program Files\wamp\www\qun\xml\b.php on line 2Warning: Invalid argument supplied for foreach() in D:\Program Files\wamp\www\qun\xml\b.php on line 3
      

  3.   

    <?xmlversion="1.0"?>自己写错了.
    <?xml version="1.0"?>
    你要先把xml文件在浏览器上试过才好.
      

  4.   

    你的a.xml格式有问题~
    至少xml和vesion之间要有空格
      

  5.   


    XML文件格式都错了,怎么载入XML文件呢?<?xmlversion="1.0"?>改为<?xml version="1.0"?>