我试图从xml中提取数据属性[value],$ xml-> xpath(" / products")显示:
[categories] => SimpleXMLElement Object ( [category] => Zapas )
[properties] => SimpleXMLElement Object (
[property] =>
Array (
[0] => SimpleXMLElement Object ( [@attributes] =>
Array (
[name] => VAL)
[value] => 1111111 )
[1] => SimpleXMLElement Object ( [@attributes] =>
Array (
[name] => manufacturer )
[value] => Nike)
[2] => SimpleXMLElement Object ( [@attributes] =>
Array (
[name] => condition )
[value] => new )
[3] => SimpleXMLElement Object ( [@attributes] =>
Array (
[name] => deliveryCosts )
[value] => 0.00 )
[4] => SimpleXMLElement Object ( [@attributes] =>
Array (
[name] => stock )
[value] => in stock )
) )
我使用下一代码来提取xml值:
$xml = simplexml_load_file("http://productType=2",'SimpleXMLElement');
foreach($xml->product as $file){
$file->categories->category;
$file->properties????
}
问题:我无法从:
中提取Nike[properties] => SimpleXMLElement Object (
[property] =>
Array (
[0] => SimpleXMLElement Object ( [@attributes] =>
Array (
[1] => SimpleXMLElement Object ( [@attributes] =>
Array (
[name] => manufacturer )
[value] => Nike)...
使用
$brand= (string)$file->properties->property[1]->attributes()
我有制造商数据(名称),但是
$brand= (string)$file->properties->property[1]->attributes()->value
无法获得耐克(价值)
我怎样才能获得属性[value]数据? 提前致谢