我有以下腳本讀取XML。但它在for循環之後停止。如果我刪除循環它運行完美。簡單的xml不支持循環到foreach
我做錯了什麼,或者我能以其他方式做到這一點?
腳本:
$xml=simplexml_load_file("test.xml");
foreach($xml->product as $child){
echo 'Title:'.$child->name.'<br>';//title
echo 'Price:'.$child->price.'<br>';//title
echo 'image:'.$child->images->image.'<br>';//image
echo 'category:'.$child->categories->category.'<br>';//categorie
foreach($child->properties->property as $property){
if($child->properties->property->attributes()->name =='brand'){
echo $child->properties->property->value.'<br>';
}
}
}
XML:
<product ID="000000000000052993">
<name> Title product</name>
<price currency="EUR">29.99</price>
<URL>http://www.url.nl</URL>
<images>
<image>product/5/2/52993_2.jpg</image>
</images>
<description><![CDATA[description.]]>
</description>
<categories>
<category>catt</category>
</categories>
<properties>
<property name="brand">
<value>PHILIPS</value>
</property>
<property name="deliveryTime">
<value>5</value>
</property>
<property name="User1">
</property>
<property name="User2">
</property>
<property name="shipping_cost">
<value>0.00</value>
</property>
<property name="User3">
</property>
<property name="EAN">
<value>8727900831733</value>
</property>
</properties>
<variations/>
</product>
把它放在一個數組應該工作 –