Results 1 to 2 of 2

Thread: SimpleXML PHP5: last items in large set

  1. #1

    Thread Starter
    Fanatic Member Matt_T_hat's Avatar
    Join Date
    Dec 2001
    Location
    '76 Male Body Evil-Errors: 666
    Posts
    774

    Question SimpleXML PHP5: last items in large set

    When I use SimpleXML it puts newer nodes at the end of the file.

    Assuming my file is large (think massive and growing) what is the best way to get the last n nodes.

    For example:

    <topic title="epic 129109 page post race">
    <post date="ages-ago">First!</post>
    ...
    <post date="seconds-ago">Thank you for that</post>
    <post date="just-now">No, thank you.</post>
    </topic>

    I don't want to kill my poor server by asking it to foreach through a growing set if I can skip to the last n nodes.

    The question is how do I do this?
    ?
    'What's this bit for anyway?
    For Jono

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: SimpleXML PHP5: last items in large set

    Your first port of call should be the XMLReader. This is better to suited to an XML dataset containing a large quantity of data as it does not load the entire data set into memory.


    However, this does not solve the problem of moving the last-nth element. You will have to call the "next()" function until you reach your desired location and you will need to record the number of occurrences of the element in an attribute of its parent element. I recommend that if you have a very large data set, you consider using a database or if the data must stay in XML format an XML database; I've used Berkeley DB XML and it is very, very fast.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width