我正在尝试获取 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 关注
- 130 浏览
添加回答
举报
0/150
提交
取消