Unable to access elements in SimpleXML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thecoolone

    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=De fault&start=0&r esults=4&query= new';
    $response=file_ get_contents($r equest);
    if ($response === false) {
    die('Request failed');}
    $phpobject = simplexml_load_ string($respons e);
    print "Printing title $phpobject->title is
    $phpobject->entry->0->link";
    echo '<pre>';
    print_r($phpobj ect);
    echo '<pre>'; }


    And this is the output:
    SimpleXMLElemen t Object
    (
    [title] =Search results for query 'new' on index Default
    [link] =SimpleXMLEleme nt Object
    (
    [@attributes] =Array
    (
    [href] =>

    [rel] =self
    [type] =application/atom+xml
    )

    )

    [author] =SimpleXMLEleme nt Object
    (
    [name] =IBM OmniFind Yahoo! Edition API Web Service
    )

    [id] =>

    [category] =SimpleXMLEleme nt 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

Working...