-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathxml-sequence-stream.php
More file actions
43 lines (33 loc) · 1.29 KB
/
xml-sequence-stream.php
File metadata and controls
43 lines (33 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/*
* 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) : '%');
}
XMLSequenceStream::clean();
stream_wrapper_unregister('xmlseq');