My xml:
<products>
<product>
<categoryName>Telewizory</categoryName>
<brandName>Sony</brandName>
<productCode>133</productCode>
<productId>14165691</productId>
<productFullName>Design Thinking dla przedsiębiorców i małych firm.</productFullName>
<productEan>3</productEan>
<productEuroPriceNetto>203.33</productEuroPriceNetto>
<productFrontendPriceNetto>220.22</productFrontendPriceNetto>
<productFastestSupplierQuantity>0</productFastestSupplierQuantity>
<deliveryEstimatedDays>5</deliveryEstimatedDays>
</product>
<product>
<categoryName>Telewizory</categoryName>
<brandName>Sony</brandName>
<productCode>133</productCode>
<productId>1416569122</productId>
<productFullName>Design not Thinking dla przedsiębiorców i małych firm.</productFullName>
<productEan></productEan>
<productEuroPriceNetto>300.33</productEuroPriceNetto>
<productFrontendPriceNetto>22.85</productFrontendPriceNetto>
<productFastestSupplierQuantity>24</productFastestSupplierQuantity>
<deliveryEstimatedDays>2</deliveryEstimatedDays>
</product>
</products>
I use XmlReader to read and parse large XML files:
$reader = new XMLReader();
$reader->open($url);
$count = 0;
$this_value = '';
//$products = array();
while($reader->read()) {
switch ($reader->nodeType) {
case XMLReader::ELEMENT:
// deal with self-closing tags
if ($reader->isEmptyElement) {
${$reader->name} = '';
$products[$count][$reader->name] = '';
}
break;
case XMLReader::TEXT:
case XMLReader::CDATA:
// save the value for storage when we get to the end of the element
$this_value = $reader->value;
break;
case XMLReader::END_ELEMENT:
if ($reader->name == 'product') {
$count++;
// print_r(array($categoryName, $brandName, $productCode, $productId, $productFullName, $productEan, $productEuroPriceNetto, $productFrontendPriceNetto, $productFastestSupplierQuantity, $deliveryEstimatedDays));
} elseif ($reader->name != 'products') {
${$reader->name} = $this_value;
//$products[$count][$reader->name] = $this_value;
// set this_value to a blank string to allow for empty tags
$this_value = '';
}
break;
case XMLReader::WHITESPACE:
case XMLReader::SIGNIFICANT_WHITESPACE:
default:
// nothing to do
break;
}
}
$reader->close();
Facing the problem, when connection with the server interrupting. I need to stop this process in this case. How? Seems here it is not possible validate whole file, but maybe are possible validate each part of this large file by element? And it is possible without XSD schema file? Can anybody put me on the right way or maybe someone already have solution for this?