bitandblack / xmlprocessor
Fast handling of xml data
Requires
- php: >=7.1
- ext-dom: *
- psr/log: ^1.1
Requires (Dev)
- bitandblack/measurement: ^0.3
- monolog/monolog: ^2.0
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^8.0 || ^9.0
- symfony/console: ^5.0
This package is auto-updated.
Last update: 2020-12-27 13:19:12 UTC
README
XMLProcessor
Fast handling of xml data.
Installation
This library is made for the use with Composer. Add it to your project by running $ composer require bitandblack/xmlprocessor
.
Usage
The Bit&Black XML Processor is up to 20 times faster in parsing huge xml data.
This is because it doesn't make use of foreach
to handle XML nodes. Instead the processor uses a while
loop and a copy of the DOMElements.
Set up the processor with your xml data:
<?php
use DOMDocument;
use BitAndBlack\XML\XMLProcessor;
$domDocument = new DOMDocument();
$domDocument->load('your_huge_file.xml');
$processor = new XMLProcessor($domDocument);
Use eachElement()
now instead of foreach
:
<?php
$processor->eachElement(
static function($dom) {
return $dom->getElementsByTagName('some_node');
},
static function($node, $key) {
var_dump('Found at position '.$key.' node with id '.$node->getAttribute('id'));
}
);
The first attribute is a function where you can set up the statement with whom you can select the nodes you want to.
The second attribute is a callback function which is called for every processed item.
eachElement()
makes a clone of the DOM to reach a fast processing so modifying the original DOM at the same time will not target the processed data.
Help
If you have questions feel free to contact us under help@bitandblack.com
.