File tree 1 file changed +8
-14
lines changed
1 file changed +8
-14
lines changed Original file line number Diff line number Diff line change @@ -154,29 +154,23 @@ var_dump($price);
154
154
*/
155
155
```
156
156
157
- Splitting data to XML fragments (with valid namespaces)
157
+ Splitting data to XML fragments by xpath (with valid namespaces)
158
158
159
159
``` php
160
- $items = function(): iterable {
161
- /** @var \Inspirum\XML\Reader\ReaderFactory $factory */
162
- $reader = $factory->create('/output/feeds/google.xml');
163
-
164
- foreach ($reader->iterateNode('/rss/channel/item', true) as $item) {
165
- yield $item->toString();
166
- }
167
- }
160
+ /** @var \Inspirum\XML\Reader\ReaderFactory $factory */
161
+ $reader = $factory->create('/output/feeds/google.xml');
168
162
169
- foreach ($items as $item) {
170
- $xml = \simplexml_load_string( $item);
171
- $id = $xml ->xpath('/item/g:id')[0] ?? null
172
- // ...
163
+ foreach ($reader->iterateNode('/rss/channel/item', true) as $item) {
164
+ $data = $item->toString( );
165
+ $id = ($item ->xpath('/item/g:id')[0] ?? null)?->getTextContent()
166
+ // ...
173
167
}
174
168
```
175
169
176
170
177
171
## System requirements
178
172
179
- * [ PHP 8.1 +] ( http://php.net/releases/8_1_0 .php )
173
+ * [ PHP 8.2 +] ( http://php.net/releases/8_2_0 .php )
180
174
* [ ext-dom] ( http://php.net/dom )
181
175
* [ ext-json] ( http://php.net/json )
182
176
* [ ext-xmlreader] ( http://php.net/xmlreader )
You can’t perform that action at this time.
0 commit comments