0

I have a PHP file that uses cURL to retrieve some XML. I now want to retrieve a value from the XML but I cannot traverse to it as I am confused with the notation.

Here's my retrieved XML:

SimpleXMLElement Object
(
[@attributes] => Array
    (
        [uri] => /fruit/apple/xml/green/pipType
    )

[result] => SimpleXMLElement Object
    (
        [JobOpenings] => SimpleXMLElement Object
            (
                [row] => Array
                    (
                        [0] => SimpleXMLElement Object
                            (
                                [@attributes] => Array
                                    (
                                        [no] => 1
                                    )
                                [FL] => Array
                                    (
                                        [0] => 308343000000092052
                                        [1] => ZR_6_JOB
                                    )
                            )
                        [1] => SimpleXMLElement Object
                            (
                                [@attributes] => Array
                                    (
                                        [no] => 2
                                    )
                                [FL] => Array
                                    (
                                        [0] => 308343000000091031
                                        [1] => ZR_5_JOB
                                    )
                            )
                    )
            )
    )
)

I have this XML stored in a variable called $xml using:

$xml = new SimpleXmlElement($data, LIBXML_NOCDATA);

Any help for how I can select the ZR_5_JOB element please?

I have tried countless times, the last effort I had was:

print_r($xml->result->JobOpenings->row[0]->FL[0]);

Could anybody please help?

(I know I will then need to do some iteration, but I'll deal with that later!)

Jonirish
  • 49
  • 6
  • Firstly, $xml->result->JobOpenings->row[0]->FL[0] would reference item 0 in FL - "308343000000091031". You need to reference the right key (FL[1]) - additionally to get the value check http://stackoverflow.com/questions/2867575/get-value-from-simplexmlelement-object – Andy Hoffner May 27 '15 at 16:24
  • Well spotted thanks; I'm going daft from looking at code today. – Jonirish May 27 '15 at 17:54

1 Answers1

0

First loop the JobOpenings rows to get each row separately and then you can access the childrens of that element in an easy way.

foreach($xml->result->JobOpenings->row as $item) {
    echo $item->FL[0] . '<br>';
}
Jonirish
  • 49
  • 6
Karl
  • 833
  • 6
  • 13