php怎么取取xml里的数据?
<?xml version='1.0' encoding='gb2312'?>
<imgList>
<pic>
<list path="/Public/images/01.jpg" smallpath="/Public/images/01.png" smallinfo="管理创造价值">http://www.china-lz.org/</list>
<list path="/Public/images/02.jpg" smallpath="/Public/images/02.png" smallinfo="价值、合作、专业、实践">http://www.china-lz.org/</list>
<list path="/Public/images/03.jpg" smallpath="/Public/images/03.png" smallinfo="七彩虹显卡十周年庆典">http://www.china-lz.org/</list>
<list path="/Public/images/04.swf" smallpath="/Public/images/04.png" smallinfo="Colorful S101">http://www.china-lz.org/</list>
</pic>
<rollTime fade_in="10">6</rollTime>
<text font="微软雅黑" size="14" bold="true" color="0xfffffff"></text>
</imgList>
我想取<list path="/Public/images/01.jpg" smallpath="/Public/images/01.png" smallinfo="管理创造价值">http://www.china-lz.org/</list>里面path,smallinfo,url
放到数组里,我用$xml = simplexml_load_file('file.xml'),foreach $xml->pic 取不出来。
------解决方案--------------------
DOM解法:
PHP code
$doc = new DomDocument();
$doc->load("file.xml");
$lists=$doc->getElementsByTagName("list");
foreach($lists as $list){
$path=$list->getAttribute("path");
$smallinfo=$list->getAttribute("smallinfo");
$arr[]=array('path'=>$path,'smallinfo'=>$smallinfo,'url'=>$list->nodeValue);
}
print_r($arr);