0

I have this output when reading an XML file.

http://pastebin.com/NfNHBaHt

SimpleXMLElement Object
(
    [GetAllDomains] => SimpleXMLElement Object
        (
            [DomainDetail] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [DomainName] => domain1.com
                            [DomainNameID] => 153033597
                            [expiration-date] => 3/1/2017 2:23:56 PM
                            [lockstatus] => Locked
                            [AutoRenew] => Yes
                        )

                    [1] => SimpleXMLElement Object
                        (
                            [DomainName] => domain2.com
                            [DomainNameID] => 153043233
                            [expiration-date] => 5/25/2017 5:45:00 PM
                            [lockstatus] => Not Locked
                            [AutoRenew] => Yes
                        )

                )

            [domaincount] => 2
            [UserRequestStatus] => DomainBox
        )

    [Command] => GETALLDOMAINS
    [APIType] => API
    [Language] => eng
    [ErrCount] => 0
    [ResponseCount] => 0
    [MinPeriod] => SimpleXMLElement Object
        (
        )

    [MaxPeriod] => 10
    [Server] => SJL0VWRESELL_T1
    [Site] => eNom
    [IsLockable] => SimpleXMLElement Object
        (
        )

    [IsRealTimeTLD] => SimpleXMLElement Object
        (
        )

    [TimeDifference] => +0.00
    [ExecTime] => 0.094
    [Done] => true
    [RequestDateTime] => 5/25/2015 9:47:21 AM
    [debug] => SimpleXMLElement Object
        (
        )

)

the above output is being shown by using the print_r function in PHP

how can i loop through the array of DomainDetail in PHP using a foreach loop

i tried using print_r($xml->DomainDetail); and print_r($xml["DomainDetail"]);

but nothing is being shown using this print_r

charlie
  • 415
  • 4
  • 35
  • 83
  • Convert the simleXMLObject to an array -> http://stackoverflow.com/questions/6167279/converting-a-simplexml-object-to-an-array – OllyBarca May 25 '15 at 16:56

1 Answers1

1
foreach($xml->GetAllDomains->DomainDetail as $domainDetail) {
    echo $domainDetail->DomainName, "\n";
    echo $domainDetail->DomainNameID, "\n";
    echo $domainDetail->{'expiration-date'}, "\n";
    // etc..
}
Federkun
  • 36,084
  • 8
  • 78
  • 90