1

After calling the prestashop webservice, I recieved the response as shown below:

SimpleXMLElement Object
(
    [order] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [id] => 1
                        )

                )

            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [id] => 2
                        )

                )

        )

)

I tried to retrive the content by looping as shown below:

foreach($resources as $resource){
    echo '<pre>';
    print_r($resource['id']);
    echo '</pre>';
}

This gives me:

SimpleXMLElement Object
(
    [0] => 1
)
SimpleXMLElement Object
(
    [0] => 2
)

How can I retrieve 1 and 2 which are the values of these objects? thanks

lomse
  • 4,045
  • 6
  • 47
  • 68

1 Answers1

1

I hate simplexml...

<?php
$xml = file_get_contents('xml.xml');
$xml = new SimpleXMLElement($xml);

foreach($xml as $key => $value)
{
        $attrs = $value->attributes();
        foreach($attrs as $attr_k => $attr_v)
                echo $attr_k.": ".$attr_v."\n";
}
user229044
  • 232,980
  • 40
  • 330
  • 338
ZiTAL
  • 3,466
  • 8
  • 35
  • 50