1
とXMLをループ:は、私はこのようなXMLカール応答を持つ名前空間PHP
<ns2:categorys xmlns:ns2="http://skt.tmall.business.openapi.spring.service.client.domain">
<ns2:category>
<depth>1</depth>
<dispengnm>Women Clothing</dispengnm>
<dispnm>Pakaian Wanita</dispnm>
<dispno>1</dispno>
<parentdispno>0</parentdispno>
</ns2:category>
<ns2:category>
<depth>2</depth>
<dispengnm>Dresses & Suits</dispengnm>
<dispnm>Gaun & Terusan</dispnm>
<dispno>2</dispno>
<parentdispno>1</parentdispno>
</ns2:category>
</ns2:categorys>
私はこのコードを使用して<ns2:category>
内のデータを取得しようとしました:
$return = curl_exec($ch);
$return= simplexml_load_string($return);
$categories = $return->children('ns2', true);
echo "<pre>";
var_dump(count($categories));
foreach ($categories as $category) {
print_r($category->depth);
}
しかし、私が得たすべてがあります:あなたがgetNamespaces
befor true
に設定する必要があり
int(2)
SimpleXMLElement Object
(
)
SimpleXMLElement Object
(
)
内側に包まれますように、子どもたち関数を呼び出す必要がループ内おかげで、それは魔法のように動作男 –