sdowney1 Posted February 20, 2011 Share Posted February 20, 2011 this retrieves data from a webservice at Library of Congress for example this here http://www.loc.gov/standards/sru/simple.html What I want to do is process the XML? into a string of usable text to put in a mysql database Am I getting XML back or what? save it and run it to see. In firefox, it shows xml headers, in chrome just the text elements. <?PHP //from here http://www.devshed.com/c/a/PHP/Fetching-Search-Results-as-Serialized-Arrays-with-Yahoo-Web-Services-and-PHP-5/1/ //http://php.net/manual/en/book.simplexml.php // example using LOC SRU Search Web Service - search results are displayed in raw XML format try{ $request='http://z3950.loc.gov:7090/voyager?version=1.1&operation=searchRetrieve&query=dinosaur&startRecord=2&maximumRecords=5'; // trigger the http request if(!$results=file_get_contents($request)){throw new Exception('Error requesting LOC SRU Web service');} // display the results in XML format header('Content-type:text/xml;charset=iso-8859-1'); echo $results; }//end of try catch(Exception $e){echo $e->getMessage();exit();} $xml = simplexml_load_string($result); print_r($xml); //print_r ($xmlarray); ?> Quote Link to comment Share on other sites More sharing options...
sdowney1 Posted February 20, 2011 Author Share Posted February 20, 2011 adding some code I can save the xml to a file so maybe now can work with it the file I found has to exist and have read and write permissions <?PHP //from here http://www.devshed.com/c/a/PHP/Fetching-Search-Results-as-Serialized-Arrays-with-Yahoo-Web-Services-and-PHP-5/1/ //http://php.net/manual/en/book.simplexml.php // example using LOC SRU Search Web Service - search results are displayed in raw XML format try{ $request='http://z3950.loc.gov:7090/voyager?version=1.1&operation=searchRetrieve&query=dinosaur&startRecord=2&maximumRecords=5'; // trigger the http request //if(!$results=file_get_contents($request)){throw new Exception('Error requesting LOC SRU Web service');} // display the results in XML format //header('Content-type:text/xml;charset=iso-8859-1'); //echo $results; }//end of try catch(Exception $e){echo $e->getMessage();exit();} $filename = dirname(__FILE__)."/loc.xml"; $raw_xml = file_get_contents($request); print $raw_xml; $fp = fopen($filename, "w"); fwrite($fp, $raw_xml); fclose ($fp); ?> Quote Link to comment Share on other sites More sharing options...
sdowney1 Posted February 20, 2011 Author Share Posted February 20, 2011 file_get_contents, does not work on the hosted site??? yet works locally on my localhost. it will echo the $request BUT NEVER returns anything for $raw_xml $raw_xml = file_get_contents($request); echo $raw_xml; I tried this on 2 hosted sites and it does not work. It creates the file loc.xml, but it never has any contents 0 bytes the file loc.xml has read - write permissions for everyone. Anyone have a thought as to why this is happening? $request='http://z3950.loc.gov:7090/voyager?version=1.1&operation=searchRetrieve&query=dinosaur&startRecord=2&maximumRecords=5'; echo $request; $filename = dirname(__FILE__)."/loc.xml"; $raw_xml = file_get_contents($request); echo $raw_xml; $fp = fopen($filename, "w"); fwrite($fp, $raw_xml); fclose ($fp); Quote Link to comment Share on other sites More sharing options...
sdowney1 Posted February 20, 2011 Author Share Posted February 20, 2011 well, It must be the free hosting service blocks web service calls Does someone know of a free hosting service that allows web service calls? any other ideas? 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.