Jump to content

laterooms


knutsford
 Share

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
Link to comment
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]).

Link to comment
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.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...