Retrieving XML nodes using IDs, but in the XML order
Posted: Wed Oct 21, 2009 7:03 am
This is a pretty obscure case, so pls bear with me.
I have an XML file which is essentially a site map, containing details of pages on my site, with a unique ID for each page.
Users can browse the site and add pages of interest to a 'print basket', which writes the ID for each page into a cookie (pipe-separated), so the cookie value could look like this: "1|12|3|28|14" for example. Each page ID is appended to the end of the list in the cookie, so they appear in the order in which the user has added them.
I have a page which retrieves and displays the content from all the pages the user has added, but I need to find a way of getting the pages in the order in which they appear in the XML, not the order they appear in the cookie (so the structure of the retrieved content makes sense).
One solution would be to iterate through every node in the XML, and check whether the ID is in the cookie or not, but this seems pretty inefficient, particularly if there are lots of pages in the XML.
Is there a way to take my unordered list of IDs (split into an array), and sort them into the same order in which they appear in the XML structure?
Thanks,
Mike
I have an XML file which is essentially a site map, containing details of pages on my site, with a unique ID for each page.
Users can browse the site and add pages of interest to a 'print basket', which writes the ID for each page into a cookie (pipe-separated), so the cookie value could look like this: "1|12|3|28|14" for example. Each page ID is appended to the end of the list in the cookie, so they appear in the order in which the user has added them.
I have a page which retrieves and displays the content from all the pages the user has added, but I need to find a way of getting the pages in the order in which they appear in the XML, not the order they appear in the cookie (so the structure of the retrieved content makes sense).
One solution would be to iterate through every node in the XML, and check whether the ID is in the cookie or not, but this seems pretty inefficient, particularly if there are lots of pages in the XML.
Is there a way to take my unordered list of IDs (split into an array), and sort them into the same order in which they appear in the XML structure?
Thanks,
Mike