<?php
$products = array();
$i=0;
$xmlReader = new XMLReader();
$xmlReader->open('cyril.xml');
while($xmlReader->read()) {
// check to ensure nodeType is an Element not attribute or #Text
if($xmlReader->nodeType == XMLReader::ELEMENT) {
//skip the first node which is the parent node for each product
$xmlReader->read();
//read all child nodes
while($xmlReader->read()){
$value = $xmlReader->value;
//if value was embeded in CDATA node then read this value
if($xmlReader->nodeType == XMLReader::CDATA){
$value = $xmlReader->value;
$xmlReader->read();
}
//end of product node - exit node
if($xmlReader->nodeType == XMLReader::END_ELEMENT && $xmlReader->localName == 'produit') {
break;
}
//store your product data
$products[$i][$xmlReader->localName] = $value;
}
}
}
$xmlReader->close();
var_dump($products)
Hope this helps someone some day.
-> = -> pff...
RépondreSupprimer