使用DOMXPath php将XML更改为Cakephp友好数组
有没有一种方法可以将XML转换为Cakephp友好的数组,而不必在php中的DOMXpath中使用太多查询 下面是我得到的,但我似乎无法访问属性,getAttributes函数给了我一个错误使用DOMXPath php将XML更改为Cakephp友好数组,php,xml,cakephp,xpath,Php,Xml,Cakephp,Xpath,有没有一种方法可以将XML转换为Cakephp友好的数组,而不必在php中的DOMXpath中使用太多查询 下面是我得到的,但我似乎无法访问属性,getAttributes函数给了我一个错误 $dom = new DomDocument("1.0", "ISO-8859-1"); $dom->load($xmlUrl); $array = new DomXPath($dom); $state = $array->query("//mo
$dom = new DomDocument("1.0", "ISO-8859-1");
$dom->load($xmlUrl);
$array = new DomXPath($dom);
$state = $array->query("//month/state");
$dwelling_type = $array->query("//dwelling_type[@code]");
$typical_value = $array->query("//dwelling_type/typical_value");
$dom = $array->query("//dwelling_type/dom");
$discount = $array->query("//dwelling_type/discount");
$acr = $array->query("//dwelling_type/acr");
$renters = $array->query("//dwelling_type/renters");
$vacancy = $array->query("//dwelling_type/vacancy");
$yield = $array->query("//dwelling_type/yield");
$som = $array->query("//dwelling_type/som");
$search_dsr = $array->query("//dwelling_type/search_dsr");
$dsr = $array->query("//dwelling_type/dsr");
$sr = $array->query("//dwelling_type/sr");
//$array = Xml::toArray($array);
for($i=0;$i<$typical_value->length;$i++){
//$state = $dsr_data->getElementsByTagName('state');
$dsr_stats[$i] = array(
//'state' => $state->item($i)->getAttribute('code'),
'dwelling_type' => $dwelling_type->item($i)->getAttribute('code'),
'typical_value' => $typical_value->item($i)->nodeValue,
'dom' => $dom->item($i)->nodeValue,
'discount' => $discount->item($i)->nodeValue,
'acr' => $acr->item($i)->nodeValue,
'renters' => $renters->item($i)->nodeValue,
'vacancy' => $vacancy->item($i)->nodeValue,
'yield' => $yield->item($i)->nodeValue,
'som' => $som->item($i)->nodeValue,
'search_dsr' => $search_dsr->item($i)->nodeValue,
'dsr' => $dsr->item($i)->nodeValue,
'sr' => $sr->item($i)->nodeValue
);
}
$dom=新的DomDocument(“1.0”、“ISO-8859-1”);
$dom->load($xmlUrl);
$array=newdomxpath($dom);
$state=$array->query(//month/state);
$HOLLING\U type=$array->query(//HOLLING\U type[@code]”);
$typical\u value=$array->query(//homing\u type/typical\u value);
$dom=$array->query(“//住宅类型/dom”);
$discount=$array->query(“//住宅类型/折扣”);
$acr=$array->query(“//住宅类型/acr”);
$renters=$array->query(“//住宅类型/renters”);
$EXPANCE=$array->query(//HOLLING_type/EXPANCE”);
$yield=$array->query(“//住宅类型/yield”);
$som=$array->query(“//住宅类型/som”);
$search\u dsr=$array->query(//居住类型/search\u dsr);
$dsr=$array->query(“//住宅类型/dsr”);
$sr=$array->query(“//住宅类型/sr”);
//$array=Xml::toArray($array);
对于($i=0;$i长度;$i++){
//$state=$dsr_data->getElementsByTagName('state');
$dsr_stats[$i]=阵列(
//'state'=>$state->item($i)->getAttribute('code'),
“住宅类型”=>$住宅类型->项目($i)->getAttribute('code'),
“典型值”=>$typical\u value->item($i)->nodeValue,
'dom'=>$dom->item($i)->nodeValue,
“折扣”=>$折扣->项目($i)->节点价值,
“acr”=>acr>item($i)->nodeValue,
'renters'=>$renters->item($i)->nodeValue,
“空缺”=>$空缺->项目($i)->节点价值,
“收益率”=>$yield->item($i)->nodeValue,
'som'=>$som->item($i)->nodeValue,
'search\u dsr'=>$search\u dsr->item($i)->nodeValue,
“dsr”=>dsr->item($i)->nodeValue,
'sr'=>sr>item($i)->nodeValue
);
}
我使用php函数将xml读入类似数组的结构中