0
phpのDOMXpathで多すぎるクエリを使わずにXMLをCakephpのフレンドリーな配列に変換する方法はありますか?DOMXPathでXMLをCakephpフレンドリーな配列に変更するPHP
以下は私が持っているものですが、アクセス属性とgetAttributes関数でエラーが発生するようです。
$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
);
}