You are here: Unable to access elements in SimpleXML « PHP Programming Language « IT news, forums, messages
Unable to access elements in SimpleXML

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация