Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-novotny committed Oct 17, 2023
1 parent 96dffbc commit 063aaa5
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,29 +154,23 @@ var_dump($price);
*/
```

Splitting data to XML fragments (with valid namespaces)
Splitting data to XML fragments by xpath (with valid namespaces)

```php
$items = function(): iterable {
/** @var \Inspirum\XML\Reader\ReaderFactory $factory */
$reader = $factory->create('/output/feeds/google.xml');

foreach ($reader->iterateNode('/rss/channel/item', true) as $item) {
yield $item->toString();
}
}
/** @var \Inspirum\XML\Reader\ReaderFactory $factory */
$reader = $factory->create('/output/feeds/google.xml');

foreach ($items as $item) {
$xml = \simplexml_load_string($item);
$id = $xml->xpath('/item/g:id')[0] ?? null
// ...
foreach ($reader->iterateNode('/rss/channel/item', true) as $item) {
$data = $item->toString();
$id = ($item->xpath('/item/g:id')[0] ?? null)?->getTextContent()
// ...
}
```


## System requirements

* [PHP 8.1+](http://php.net/releases/8_1_0.php)
* [PHP 8.2+](http://php.net/releases/8_2_0.php)
* [ext-dom](http://php.net/dom)
* [ext-json](http://php.net/json)
* [ext-xmlreader](http://php.net/xmlreader)
Expand Down

0 comments on commit 063aaa5

Please sign in to comment.