Posted by thecoolone on 01/25/07 13:38
I am creating a REST API in php that parses the XML result given by IBM
Omnifind.
here's the php code:
$query=$_GET['query'];
$request='http://localhost:8080/api/search?index=Default&start=0&results=4&query=new';
$response=file_get_contents($request);
if ($response === false) {
die('Request failed');}
$phpobject = simplexml_load_string($response);
print "Printing title $phpobject->title is
$phpobject->entry->0->link";
echo '<pre>';
print_r($phpobject);
echo '<pre>'; }
And this is the output:
SimpleXMLElement Object
(
[title] => Search results for query 'new' on index Default
[link] => SimpleXMLElement Object
(
[@attributes] => Array
(
[href] =>
http://localhost:8080/api/search?index=Default&start=0&results=4&query=new
[rel] => self
[type] => application/atom+xml
)
)
[author] => SimpleXMLElement Object
(
[name] => IBM OmniFind Yahoo! Edition API Web Service
)
[id] =>
http://localhost:8080/api/search?index=Default&start=0&results=4&query=new
[category] => SimpleXMLElement Object
(
[@attributes] => Array
(
[term] => Default
[label] => Default
) )
I am able to access the elements in this way $phpobject->title. BUT the
problem is that it only works for elements that have a value, like
"title" and "id" in the above output.
When i try to access the "href" in "link" by using
$phpobject->link->attributes->href;
and "term" in "category" by using
$phpobject->category->attributes->term; it doesnt work.
what could be the reason? How to access elements that contain "@"?
thanx in advance
Navigation:
[Reply to this message]
|