如何遍历XML文件

WBOY
Release: 2016-06-20 12:34:31
Original
966 people have browsed it

怎么遍历xml文件  需要放进数据库里面吗? 


  

      水果
  乔木
  花类
  其他
    
   

      
  
  其他
    

  


我想遍历后在前端的效果是以这种效果的


回复讨论(解决方案)

怎么显示就自己组织吧

$s = <<<EOF<?xml version="1.0" encoding="utf-8"?><MedicalDiagnosis dataBlock="Root0">  <Evaluations total="2">	<Evaluation data="植物系统">	  <OBJECT data="苹果,梨">水果</OBJECT>	  <OBJECT data="竹子,富贵竹">乔木</OBJECT>	  <OBJECT data="菊花,康乃馨">花类</OBJECT>	  <OBJECT data="">其他</OBJECT>	</Evaluation>   	<Evaluation data="动物系统">	  <OBJECT data="老虎,狮子">陆</OBJECT>	  <OBJECT data="鱼,海马">海</OBJECT>	  <OBJECT data="">其他</OBJECT>	</Evaluation>  </Evaluations></MedicalDiagnosis>EOF;$x = simplexml_load_string($s);$data = [];foreach($x->Evaluations as $Evaluations){	foreach($Evaluations->Evaluation as $Evaluation){		$tmpData = current($Evaluation->attributes()->data);		if(!isset($data["$tmpData"])){			$data["$tmpData"] = [];		}		foreach($Evaluation->OBJECT as $OBJECT){			$data["$tmpData"]["$OBJECT"] = current($OBJECT->attributes()->data);		}	}}print_r($data);/*Array(    [植物系统] => Array        (            [水果] => 苹果,梨            [乔木] => 竹子,富贵竹            [花类] => 菊花,康乃馨            [其他] =>         )    [动物系统] => Array        (            [陆] => 老虎,狮子            [海] => 鱼,海马            [其他] =>         ))*/
Copy after login
Copy after login

怎么显示就自己组织吧

$s = <<<EOF<?xml version="1.0" encoding="utf-8"?><MedicalDiagnosis dataBlock="Root0">  <Evaluations total="2">	<Evaluation data="植物系统">	  <OBJECT data="苹果,梨">水果</OBJECT>	  <OBJECT data="竹子,富贵竹">乔木</OBJECT>	  <OBJECT data="菊花,康乃馨">花类</OBJECT>	  <OBJECT data="">其他</OBJECT>	</Evaluation>   	<Evaluation data="动物系统">	  <OBJECT data="老虎,狮子">陆</OBJECT>	  <OBJECT data="鱼,海马">海</OBJECT>	  <OBJECT data="">其他</OBJECT>	</Evaluation>  </Evaluations></MedicalDiagnosis>EOF;$x = simplexml_load_string($s);$data = [];foreach($x->Evaluations as $Evaluations){	foreach($Evaluations->Evaluation as $Evaluation){		$tmpData = current($Evaluation->attributes()->data);		if(!isset($data["$tmpData"])){			$data["$tmpData"] = [];		}		foreach($Evaluation->OBJECT as $OBJECT){			$data["$tmpData"]["$OBJECT"] = current($OBJECT->attributes()->data);		}	}}print_r($data);/*Array(    [植物系统] => Array        (            [水果] => 苹果,梨            [乔木] => 竹子,富贵竹            [花类] => 菊花,康乃馨            [其他] =>         )    [动物系统] => Array        (            [陆] => 老虎,狮子            [海] => 鱼,海马            [其他] =>         ))*/
Copy after login
Copy after login


大神,为什么我直接显示找不到页面啊

找不到网页....那是你服务器的错误吧,或者链接写错了...

找不到网页....那是你服务器的错误吧,或者链接写错了...


大神我把【】改为array()就可以了  大神这个输出的数组怎么输出到thinkphp前端? volist 怎么嵌套输出

[] 是 php 5.4+ 的写法

分配到前台
$this->assign('data',$data);


怎么循环显示,要加什么样式 ...就是你的事了
http://document.thinkphp.cn/manual_3_2.html#volist

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template