beermaker74 Posted March 1, 2007 Share Posted March 1, 2007 ok i am trying to parse some xml and it is becoming a royal pain in my arse. $base = 'http://google.com/base/feeds/snippets/-/'; $params = 'rental+%5blocation:@%22San+Francisco,CA%22%2b50mi%5d&max-results=3'; $url = $base . 'housing?bq=' . $params; $c = curl_init($url); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($c); curl_close($c); $dom = domxml_open_mem($response, DOMXML_LOAD_PARSING, $errors); foreach ($dom->documentElement->childNodes as $books) { if (($books->nodeType == 1) && ($books->nodeName == "entry")) { foreach ($books->childNodes as $theBook) { if (($theBook->nodeType == 1) && ($theBook->nodeName == "id")) { $id = $theBook->textContent; } It gives me an error in the foreach statement. It works fine on my local machine with php5. But not on my server with php4.4.4 here is the error Warning: Invalid argument supplied for foreach() before I had $doc = new DOMDocument(); $doc->load( 'books1.xml' ); to start the dom and I was getting errors. undefined function etc. dom needs a parameter. Once again worked fine on php5 but not on my server. So i changed that to $dom = domxml_open_mem($response, DOMXML_LOAD_PARSING, $errors); and that seemed to solve that problem but then the foreach problem came up. Somebody mentioned that the syntax I am using is for php 5. They recomended changing' foreach ($dom->documentElement->childNodes as $books) { to foreach ($dom->document_element->child_nodes as $books) { it is still giving me the same error my main goal in this is to display feeds from google base. So all i need to do is parse and display the feed in my own format. This code does exactly what I want in php 5. but im stuck woth 4.4.4 Quote Link to comment Share on other sites More sharing options...
btherl Posted March 1, 2007 Share Posted March 1, 2007 The DOM interface changed between php 4 and 5. Check these sites: http://sg.php.net/manual/en/ref.dom.php (v5) http://sg.php.net/manual/en/ref.domxml.php (v4) Quote Link to comment Share on other sites More sharing options...
beermaker74 Posted March 2, 2007 Author Share Posted March 2, 2007 Ok going thru the xml dom for php 4 i came up with this that works for anybody else having the same problem $dom = domxml_open_mem($response, DOMXML_LOAD_PARSING, $errors); $noderoot = $dom->document_element(); $childnodes = $noderoot->child_nodes(); foreach($childnodes as $books) { if (($books->node_type() == 1) && ($books->node_name() == "entry")) { foreach ($books->child_nodes() as $theBook) { if (($theBook->node_type() == 1) && ($theBook->node_name() == "id")) { $id = $theBook->get_content(); } if (($theBook->node_type() == 1) && ($theBook->node_name() == "published")) { $published = $theBook->get_content(); } if (($theBook->node_type() == 1) && ($theBook->node_name() == "updated")) { $updated = $theBook->get_content(); } /* if (($theBook->node_type() == 1) && ($theBook->node_name() == "category")) { $category = $theBook->get_attribute('term'); }*/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.