Answer the question
In order to leave comments, you need to log in
How to read attribute of child element in XMLReader?
There is a very large XML that is read sequentially using an XMLReader
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://webmaster.yandex.ru/schemas/feed/realty/2010-06">
<generation-date>2019-11-10T15:00:19+03:00</generation-date>
<offer internal-id="14">
<image>plan.jpg</image>
<image>1.jpg</image>
<image tag="plan">2.jpg</image>
<image>3.jpg</image>
<image>4.jpg</image>
</offer>
<offer>
…
</offer>
</feed>
offer
and select only image tag="plan" among other attributes. $reader = new XMLReader();
$reader->open('test.xml');
$doc = new DOMDocument;
while ($reader->read() && $reader->name !== 'offer');
while ($reader->name === 'offer')
{
$node = simplexml_import_dom($doc->importNode($reader->expand(), true));
print_r ($node->attributes()); // internal-id] => 14
$reader->next('offer');
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question