我正在嘗試獲取 catId 值。但我只能看到類別值。我的 xml 文件如下所示:<sample> <Item ItemNumber="00000088" FormattedItemNumber="00000-088"> <CompatibleModels /> <Category CatId="160" > test 123 </Category> <Images /> <Documents /> <RequiredItems /> </Item></sample>$xml = simplexml_load_file("test.xml");print_r($xml);[sample] => Array ( [0] => SimpleXMLElement Object ( [@attributes] => Array ( [ItemNumber] => 00000088 [FormattedItemNumber] => 00000-088 ) [Category] => Bags/Luggage 123 )如何獲得 CatId 值?為什么缺少 cateId 值?
3 回答

紅糖糍粑
TA貢獻1815條經驗 獲得超6個贊
您可以使用以下代碼段循環并獲取它,請參閱內聯文檔以獲取解釋
$xml1 = simplexml_load_file("test.xml") or die("Error: Cannot create object");
foreach ($xml1->children() as $items1) { // children mean item
echo ($items1->category['catid']); // for category tag get catid attribute
}
- 3 回答
- 0 關注
- 152 瀏覽
添加回答
舉報
0/150
提交
取消