Guest User

Untitled

a guest
Aug 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. Can SimpleXML load only a partial of a XML?
  2. $feed = 'rss file';
  3. $xml = simplexml_load_file($feed); //not the entire feed though
  4.  
  5. $xml = simplexml_load_file($feed);
  6. $top10 = $xml->xpath('/rss/channel/item[position() <= 10]');
  7.  
  8. foreach($top10 as $item) {
  9. // output $item;
  10. }
  11.  
  12. $xmlr = new XMLReader();
  13. $xmlr->open('path/to/file');
  14. // ...
  15. // move the pointer with $xmlr->read(), $xmlr->next(), etc. to the required
  16. // elements and read them with simplexml_load_string($xmlr->readOuterXML()), etc.
  17. // ...
  18. $xmlr->close();
Add Comment
Please, Sign In to add comment