0
我已经阅读了大约数百个关于该命令的SO条目,但是我无法使其工作。我真的不明白我做错了什么。我确实在做一些明显愚蠢的事情,但目前我看不到它。SimpleXMLElement:正在检索命名空间属性
这是我在做什么:
$shopUrl = "http://api.spreadshirt.net/api/v1/shops/614852/productTypes?".
"locale=de_DE&fullData=false&limit=20&offset=0"
$ch = curl_init($shopUrl);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$result = curl_exec($ch);
curl_close($ch);
$products = new SimpleXMLElement($result);
foreach ($products->productType as $product) {
$resources = $product->children('http://www.w3.org/1999/xlink');
$resEntity = array(
'id' => (int)$product->attributes()->id,
'name' => (string)$product->name[0],
'price' => (string)$product->price[0]->vatIncluded[0],
'preview' => $resources
);
echo '<pre>'.print_r($resEntity, true).'</pre>';
}
此输出我
Array
(
[id] => 6
[name] => Männer T-Shirt klassisch
[price] => 9.90
[preview] => SimpleXMLElement Object
(
[@attributes] => Array
(
[href] => http://api.spreadshirt.net/api/v1/shops/614852/productTypes/6
)
)
)
现在我试图访问HREF-属性,但我试过的所有东西,如$resources->attributes()->href
或$resources['href']
,但PHP继续说Node no longer exists
。
谢谢!这像一个魅力。 ''preview'=>(string)$ attribs-> href [0]' – marekventur 2011-05-07 15:32:59