Jump to content

xml webservice process into string??


sdowney1

Recommended Posts

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);

?>

Link to comment
Share on other sites

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);


?>

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.