PHP code example of borsodigerii / php-xml-chunker
1. Go to this page and download the library: Download borsodigerii/php-xml-chunker library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$chunkSize = 1000; // Max. 1000 shopItems per chunk
$xmlfile = "feed.xml"; // Input file
$outPrefix = "feed-"; // Prefix for chunk-files
$checkingTags = array("weight_kg"); // Tags to be validated (to which the validation function will be called)
// validation function
function validation($data, $tag) {
if($tag == "weight_kg"){
if(!empty($data) && intval($data) > 10) return true;
}
return false;
}
// Tags to be counted with $chunkSize
$mainTag = "shopItem";
// Root tag/element, that is only present once in the xml file
$rootTag = "Shop";
// Creating the chunker instance, and running the Chunker
$chunker = new Chunker\Chunker($xmlfile, $chunkSize, $outPrefix, "validation", $chekingTags);
$chunker.chunkXML($mainTag, $rootTag);
bash
$ composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.