elecena / xml-iterator
Memory efficient and fast XML parser with iterator interface
Installs: 1 009
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 1
Requires
- php: ^8.1
- ext-xml: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.22
- phpunit/phpunit: ^10.3
This package is auto-updated.
Last update: 2024-12-04 21:10:34 UTC
README
Memory efficient and fast XML parser with the iterator interface.
Usage example
Getting the list of sub-sitemaps in the remote XML sitemap file.
use Elecena\XmlIterator\XMLParser; use Elecena\XmlIterator\Nodes\XMLNodeOpen; use Elecena\XmlIterator\Nodes\XMLNodeContent; require 'vendor/autoload.php'; $stream = fopen('https://elecena.pl/sitemap.xml', mode: 'rt'); foreach(new XMLParser($stream) as $node) { if ($node instanceof XMLNodeContent && $node->name === 'loc') { echo "Sub-sitemap found: {$node->content}\n"; } elseif ($node instanceof XMLNodeOpen && $node->name === 'sitemapindex') { echo "Sitemap index node found, attributes: " . print_r($node->attributes, return: true) . "\n"; } } fclose($stream);
The above will give you:
Sitemap index node found: Array
(
[xmlns] => http://www.sitemaps.org/schemas/sitemap/0.9
)
Sub-sitemap found: https://elecena.pl/sitemap-001-search.xml.gz
Sub-sitemap found: https://elecena.pl/sitemap-002-shops.xml.gz
Sub-sitemap found: https://elecena.pl/sitemap-003-pages.xml.gz
Sub-sitemap found: https://elecena.pl/sitemap-004-datasheets.xml.gz
Sub-sitemap found: https://elecena.pl/sitemap-005-datasheets.xml.gz
Sub-sitemap found: https://elecena.pl/sitemap-006-datasheets.xml.gz
(...)