Jump to content
knutsford

laterooms

Recommended Posts

I am calling the xml file from laterooms using $xml = simplexml_load_file("http://xmlfeed.laterooms.com/index.aspx?aid=11929&rtype=4&kword=" . $County[0]); where $County[0] is the county name The I am using a loop to echo the contents of 5 of the child nodes foreach ($xml->hotel as $hotel){ } It is very slow so is there a quicker way of using the xml file? There are umpteen child nodes for each Hotel which I don't need which will be slowing it down to start with. Thanks

  • Like 1

Share this post


Link to post
Share on other sites

Yes, there is - xpath(). You can find more about the XPath syntax itself at W3Schools' XPath tutorial.By using XPath, you can limit your loop to an arbitrary collection of nodes that you can then process, as opposed to going through all nodes. For XPath to have any performance benefit though, the XPath should be as specific as possible (e.g. xpath("/root/hotel[1]") as opposed to xpath("//hotel")[0]).

Share this post


Link to post
Share on other sites

Well, if that's the case, you can use XMLReader. You can't use XPath with it, and you need to process nodes from top to bottom one by one (including every child node in all depths), but once you process the last node you need, you can just close() the reader, so you'll eliminate the overhead required to process all information. XMLReader is particularly useful (infact required) for XML documents that would otherwise exhaust the server's memory, as it keeps only one node at a time.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...