prewk / xml-string-streamer

Stream large XML files with low memory consumption.
MIT License
356 stars 49 forks source link

can UniqueNode be used with guzzle stream reader? #47

Closed ronnievisser closed 7 years ago

ronnievisser commented 7 years ago

Hi,

Can we use the UniqueNode parser together with the guzzle stream reader repository?

thanks

prewk commented 7 years ago

Hi!

Absolutely, require both:

composer require prewk/xml-string-streamer
composer require prewk/xml-string-streamer-guzzle

And then use them like this:

use Prewk\XmlStringStreamer;
use Prewk\XmlStringStreamer\Stream;
use Prewk\XmlStringStreamer\Parser;

$url = "http://example.com/really-large-xml-file.xml";

$CHUNK_SIZE = 1024;
$stream = new Stream\Guzzle($url, $CHUNK_SIZE);
$parser = new Parser\UniqueNode(array(
    "uniqueNode" => "TheNodeToCapture"
));

$streamer = new XmlStringStreamer($parser, $stream);

while ($node = $streamer->getNode()) {
    // ...
}

I think my README is a bit off regarding the constructor arguments for the parsers, unfortunately. I'll fix it!

Also, the separation of the repos doesn't make much sense anymore, considering the PHP version market shares etc. If I'd re-done it today, I would've put it all in one repo.

ronnievisser commented 7 years ago

ok thanks for the info