An API request returns an XML file. How do I echo a specific attribute?

The API call requires a specially formatted and signed http request (let's call it "$url"). So, I use this line of code:
$xml = simplexml_load_file("$url");

This line of code produces a nice big XML response, as follows:

SimpleXMLElement Object
(
    [Items] => SimpleXMLElement Object
        (
            [Request] => SimpleXMLElement Object
                (
                    [IsValid] => True
                    [ItemLookupRequest] => SimpleXMLElement Object
                        (
                            [Condition] => Used
                            [IdType] => ASIN
                            [ItemId] => 0123456789
                            [ResponseGroup] => Large
                            [VariationPage] => All
                        )

            )

        [Item] => SimpleXMLElement Object
            (
                [ASIN] => 0123456789
                [DetailPageURL] => https://www.example.com/ASIN=0123456789
                [SalesRank] => 223246
                [SmallImage] => SimpleXMLElement Object
                    (
                        [URL] => https://images.example.com/1.jpg
                        [Height] => 500
                        [Width] => 381
                    )

                [ImageSets] => SimpleXMLElement Object
                    (

etc. etc.

About half way down, you'll see the "Salesrank" is 223246. How do I echo that "223246" number?

I tried echoing it like this, but it won't work:
echo $xml->Items->Item->SalesRank;

Any thoughts, please?

I have tried

    ...and of course, when I try it now it works! Problem solved :-)

      Maryanne;11064627 wrote:

      ...and of course, when I try it now it works! Problem solved :-)

      It was tired and needed a rest before working again :p

        Write a Reply...