Can SimpleXML load only a partial of a XML?

后端 未结 2 1254
孤街浪徒
孤街浪徒 2021-01-13 13:52

Is there a way not to load the whole feed but only the first 10 tag?

$feed = \'rss file\';
$xml = simplexml_load_file(         


        
2条回答
  •  -上瘾入骨i
    2021-01-13 14:25

    With use of the XMLReader you can achieve this. This avoids the consumption of large amount of RAM.

    $xmlr = new XMLReader();
    $xmlr->open('path/to/file');
    // ...
    // move the pointer with $xmlr->read(), $xmlr->next(), etc. to the required
    // elements and read them with simplexml_load_string($xmlr->readOuterXML()), etc.
    // ...
    $xmlr->close();
    

提交回复
热议问题