xml文件
ent_scale.xml文件
<?xml version="1.0" encoding="utf-8"?>
<document name="TradeCV 数据字典(公司规模部分)">
<item key="1">50 人以下</item>
<item key="2">50~149 人</item>
<item key="4">150~499 人</item>
<item key="6">500~999 人</item>
<item key="7">1000 人以上</item>
</document>
php解析文件
ScaleXml.php文件
<?php
echo "<pre>";
$xmlfile = "ent_scale.xml"; //$xmlfile文件路径
$xmlObj = simplexml_load_file($xmlfile); //simplexml_load_file($xmlfile)转化为$xmlObj对象
$data = array();
foreach($xmlObj as $val){ //循环
$key = $val['key']; //$key就是xml中 key
$val = (array)$val; //(array)转化为数组
$text = $val[0]; //读数组的第一个元素
$data[$key] = $text;
}
print_r($data);
?>