473,395 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Unable to access elements in SimpleXML

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?ind...ts=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?ind...ts=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

Jan 25 '07 #1
0 1159

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: archi | last post by:
dear all, what would be the most simple way to multisort the (HTML) output from a simplexml file. imagine i have loaded a simplexml file with names & addresses & much more, and i would like...
1
by: hwcowan | last post by:
Hello, I have started using SimpleXML and can do most things, but there are a couple of things that I can't seem to figure out. Currently, I can: 1. Open & load an XML file 2. Manually...
10
by: soup_or_power | last post by:
The pop up window has several checkboxes. I'm unable to access the checkboxes using the handle from window.open. Any way to do this? var display; function showSugg(but_id, sugg1, sugg2, sugg3,...
6
by: Vikram | last post by:
I have added some input elements on a page using javascript at client side. when i submit the page, i am unable to access the values of input elements created using request.form. Are elements...
2
by: mandric | last post by:
Hello, Can someone please enlighten me on how to preserve the <!]> element when parsing an xml file or string with simplexml. I'm using libxml 2.6.16 and php 5.1.4. I tried a few variations,...
2
by: whisher | last post by:
Hi. I'm taking my first steps with xml and SimpleXML functions. xml.php (It could be made dynamically with a mysql result I post this snippet for example ) PHP Code xml.php: <?php $xmlstr...
1
by: Andy | last post by:
Hi, I'm running in to a little issue with SimpleXML, and wondered if anyone knew if it was normal implementation for SimpleXML, or I'm not using a correct flag, or even it's a an issue that...
3
by: bleen | last post by:
I'm trying to use SimpleXML but I've run into a conundrum. Every day an XML file is generated that this script grabs and manipulates. How can I check that the XML has no problems before creating...
0
by: ty | last post by:
I have a script that takes a xml template then adds data into it using SimpleXMLElement. I then save it using asXML into a mysql database. On my development machine at home it works fine. ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.