knutsford Posted March 6, 2012 Share Posted March 6, 2012 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 Link to comment Share on other sites More sharing options...
boen_robot Posted March 6, 2012 Share Posted March 6, 2012 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 More sharing options...
knutsford Posted March 6, 2012 Author Share Posted March 6, 2012 Possibly slightly better but still slow. I think the main problem is laterooms sending back so much information that is is slowing it down at their end Link to comment Share on other sites More sharing options...
boen_robot Posted March 6, 2012 Share Posted March 6, 2012 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.