php 解析xml文件(不需要下载其他类库)
<?php
$xml ="1.xml";
$dom = new DOMDocument();
$dom->load($xml);
$root = $dom->documentElement;
$arr=array();
foreach ($root->childNodes as $item)
{
	if($item->hasChildNodes()){

$tmp=array();
	foreach($item->childNodes as $one){
		if(!empty($one->tagName)){
		$tmp[$one->tagName]=$one->nodeValue;
		}
	}
	$arr[$item->tagName]=$tmp;
	}
}
print_r($arr);


1,xml文件如下:
<all>
<杭州>
		<拼车顺风车>http%3A%2F%2Fhz.fenlei168.com%2Fpinche%2F</拼车顺风车>
		<四S店经销商>http%3A%2F%2Fhz.fenlei168.com%2Fssss%2F</四S店经销商>
		<二手汽车>http%3A%2F%2Fhz.fenlei168.com%2Fershouche%2F</二手汽车>
		<汽车配件>http%3A%2F%2Fhz.fenlei168.com%2Fqipeijian%2F</汽车配件>
		<租车代驾陪练>http%3A%2F%2Fhz.fenlei168.com%2Fdaijia%2F</租车代驾陪练>
		<汽车服务过户>http%3A%2F%2Fhz.fenlei168.com%2Fqicheguohu%2F</汽车服务过户>
		<二手摩托车>http%3A%2F%2Fhz.fenlei168.com%2Fershoumotuo%2F</二手摩托车>
		<自行车电动车>http%3A%2F%2Fhz.fenlei168.com%2Fzixingche%2F</自行车电动车>
		<其它车辆信息>http%3A%2F%2Fhz.fenlei168.com%2Fqitache%2F</其它车辆信息>
</杭州>
<武汉>
		<拼车顺风车>http%3A%2F%2Fwh.fenlei168.com%2Fpinche%2F</拼车顺风车>
		<四S店经销商>http%3A%2F%2Fwh.fenlei168.com%2Fssss%2F</四S店经销商>
		<二手汽车>http%3A%2F%2Fwh.fenlei168.com%2Fershouche%2F</二手汽车>
		<汽车配件>http%3A%2F%2Fwh.fenlei168.com%2Fqipeijian%2F</汽车配件>
		<租车代驾陪练>http%3A%2F%2Fwh.fenlei168.com%2Fdaijia%2F</租车代驾陪练>
		<汽车服务过户>http%3A%2F%2Fwh.fenlei168.com%2Fqicheguohu%2F</汽车服务过户>
		<二手摩托车>http%3A%2F%2Fwh.fenlei168.com%2Fershoumotuo%2F</二手摩托车>
		<自行车电动车>http%3A%2F%2Fwh.fenlei168.com%2Fzixingche%2F</自行车电动车>
		<其它车辆信息>http%3A%2F%2Fwh.fenlei168.com%2Fqitache%2F</其它车辆信息>
</武汉>
</all>


以上程序会将1.xml解析,并将内容放入数组。
郑重声明:资讯 【php 解析xml文件(不需要下载其他类库)】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——