What is the best way of limiting results when using xml reader?
The code below that I’ve tried doesn’t appear to be working. Instead of just importing 3 nodes, it is still importing the entire file. I’ve looked at other forums and with credit to rrrfusco and Jose Vega from this post here is the code so far:
$i = 0;
$limit = 3;
while ($xmlReader->read()) {
if ($xmlReader->name == "product") {
$product = array();
if ($i == $limit) break;
while ($xmlReader->read()) {
$name = $xmlReader->name;
if ($name == "product") break;
switch($name) {
case $title:
case $keywords:
case $url:
if (!isset($product[$i][$name]))
$product[$i][$name] = $xmlReader->readString();
break;
}
}
$i++;
}
}
Here was my solution, domxpath did the trick. This example will limit the results to 10.