/**
  * @test
  * @dataProvider provideStreamFiles
  *
  * @param $file
  */
 public function readStream($file)
 {
     stream_wrapper_register('xmlseq', 'XMLSequenceStream');
     $path = "xmlseq://" . $file;
     $count = 0;
     $xmlFileContents = array();
     while (XMLSequenceStream::notAtEndOfSequence($path)) {
         $count++;
         $reader = new XMLReader();
         $reader->open($path, 'UTF-8', LIBXML_COMPACT | LIBXML_PARSEHUGE);
         /** @var XMLElementIterator|XMLReaderNode $elements */
         $elements = new XMLElementIterator($reader);
         $xmlFileContents[] = $elements->getSimpleXMLElement();
     }
     XMLSequenceStream::clean();
     stream_wrapper_unregister('xmlseq');
     $this->assertGreaterThanOrEqual(2, $count, 'number of sequences');
 }
        }
    }
    echo "\n";
    isset($index) || ($index = -1);
    isset($path) || ($path = '(parse error)');
    $summary = sprintf("scanning done. scanned %d elements in %d seconds. last element was %s.\n", $index + 1, microtime(true) - $start, $path);
    echo $summary;
    $errors = libxml_get_errors();
    if ($errors) {
        printf("had %d parse error(s):\n", count($errors));
        foreach ($errors as $error) {
            printf("[level: %d; code: %d; line: %d column: %d]\n%s ", $error->level, $error->code, $error->line, $error->column, $error->message);
        }
    }
    libxml_use_internal_errors($saved);
} while (substr($file, 0, 9) === 'xmlseq://' && XMLSequenceStream::notAtEndOfSequence($file));
XMLSequenceStream::clean();
stream_wrapper_unregister('xmlseq');
printf("creating scan summary in %s.\n", $outfile);
class Levels
{
    protected $levels;
    public function __construct(array $levels)
    {
        $this->levels = $levels;
    }
    public function getChildrenOfAtLevel($prefix, $level)
    {
        $children = [];
        if (isset($this->levels[$level])) {
            foreach ($this->levels[$level] as $path => $count) {
/*
 * This file is part of the XMLReaderIterator package.
 *
 * Copyright (C) 2014 hakre <http://hakre.wordpress.com>
 *
 * Example: Read XML from a file that contains a sequence of XML documents
 */
require 'xmlreader-iterators.php';
// require XMLReaderIterator library
stream_wrapper_register('xmlseq', 'XMLSequenceStream');
// file is an excerpt from https://www.google.com/googlebooks/uspto-patents-grants-text.html - ipg140107.zip
$path = 'xmlseq://compress.bzip2://data/sequence.xml.bz2';
printf("XMLReader over '%s':\n", basename($path));
$iteration = 1;
while (XMLSequenceStream::notAtEndOfSequence($path)) {
    $reader = new XMLReader();
    $reader->open($path);
    /** @var XMLElementIterator|XMLReaderNode $elements */
    $elements = new XMLElementIterator($reader);
    $rootName = $elements->getName();
    $names = array();
    $elements->setName('name');
    foreach ($elements as $index => $nameElement) {
        $name = preg_replace('~ et al.$~', '', ucfirst($nameElement));
        $names[$name] = $index;
    }
    $names = array_flip($names);
    $count = count($names);
    sort($names);
    printf("- xml #%d: %s: names (%d): %s\n", $iteration++, $rootName, $count, $names ? implode('; ', $names) : '%');