Download the PHP package borsodigerii/php-xml-chunker without Composer

On this page you can find all versions of the php package borsodigerii/php-xml-chunker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-xml-chunker

Chunker - A lightweight, glazing fast XML splitter written in PHP

GitHub Workflow Status (with event) GitHub GitHub release (with filter)

The main goal of this library is to create chunks with predefined sizes from a big XML file (or to 'split' it into multiple chunks, so to say).

The algorithm was written using the XMLParser php library, which is capable of parsing an XML file line to line (or tag to tag) without state-control, and not by a string to string comparison or simple I/O operations. This attribute of the library makes it possible to implement validation on the said tags, everytime they are parsed.

With the correct charset specified, it can handle special characters, and also parse them for validation.

Installing

You can use this library by downloading the src\Chunker.php file, and using it directly, or by using composer as your package manager:

Alternatively, you can add this library as a dependency in your composer.json file:

Then you just have to run composer update.

The minimum PHP version for this library to work, is >= 7.4.0

Usage

Simple Chunking

The implementation is Object-oriented, so in order to split the files, an instance of Chunker has to be created first.

An example of a simple Chunker instance without validation, with maximum 100 main tags/chunk, and with outputfile names of "out-{CHUNK}.xml":

Constructor variables

The following table contains the parameters that can be (and should be) passed to the constructor.

Parameter Type Description Default value Is required
$xmlfile string The big XML file to be chunked empty string Yes
$chunkSize int The number of main tags maximum in a chunk 100 No
$outputFilePrefix string The prefix that will be used as the filename for the output chunks. Pattern: '{outputFilePrefix}{CHUNK-NUMBER}.xml' 'out-' No
$validationFunction callable The validator function that is used everytime a tag found, that is inside $checkingTags. If the tag data passes the validation, it will be included in the chunks, and will not be otherwise. It has to receive two parameters: first is the data that is inside the tag to be validated, and the second is the tag itself (both being strings). It has to return a boolean. null Yes
$checkingTags array An array of tags, where their data has to be validated using the $validationFunction callable. If we don't want any validation, we can pass an empty array to this parameter, or not specify it at all since it's not required. empy array No

If any of the required parameters are empty/not specified, a Fatal error will be raised.

Launch the chunking!

After you created an instance of Chunker, and all the parameters were set, you can start the chunking process. You can do this with the Chunker::chunkXML method. An example is shown below:

This example will create xml chunks from the big file (if validation is enabled, then only the validated main tags will be included), with $chunkSize number of main tags (here it's called "item"). Every main tag is enclosed between one root tag (here it's called "root") in every file (so every chunked file will contain one root tag, and $chunkSize number of main tags inside it).

THe method returns the logging session's string conversion (see below for more information).

Logging

The class has an implemented logging feature. Everytime the Chunker::chunkXML is run, a new logging session is launched, which can be retrieved with the very same function. After its run, it returns the logging session converted into string:

It is really helpful, when something is not working for your needs, and has to be debugged from step to step. It is not neccessary to catch, so you can just call the function like its return value is void.

Examples

Basic validation

Lets say, that you have an XML file ("feed.xml") with a Shop root element, and multiple shopItem elements inside it (10.000+):

You want it to split into files named "feed-{chunk}.xml" containing 1000 shopItems maximum. And you also want to only include shopItems, that has a weight_kg tag inside, which can only be greater than 10 (or '10 kgs'). The solution is like the following:


All versions of php-xml-chunker with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package borsodigerii/php-xml-chunker contains the following files

Loading the files please wait ....