我无法解析 XML 文件。如何在循环中制作以下代码。我可以用 SimpleXML 做到这一点吗?
<Variants>
<Definition>Color=Black</Definition>
<Code/>
<Image>1744.jpg</Image>
<Stock>1</Stock>
<Price>3385.5933</Price>
<CurrencyID>1</CurrencyID>
<Suffix>TL</Suffix>
<Definition>Color=White</Definition>
<Code/>
<Image>1741.jpg</Image>
<Stock>1</Stock>
<Price>3385.5933</Price>
<CurrencyID>1</CurrencyID>
<Suffix>TL</Suffix>
</Variants>
php代码
$xmlobj = simplexml_load_file("variants.xml");
$variants = $xmlobj->Variants;
foreach ($variants as $item) {
echo " ".$item->Definition." ";
}