Page 1 of 1

PHP XML Extraction

Posted: Tue Feb 08, 2011 2:33 am
by Cisco-come-Developer
Hi Guys,

I'm currently struggling with extracting information from a SimpleXMLElement Array.

Here's the code...

Code: Select all

<pre>SimpleXMLElement Object
(
    [errorcode] => 0000
    [users] => SimpleXMLElement Object
        (
            [user] => SimpleXMLElement Object
                (
                    [username] => ###########
                    [txtypes] => SimpleXMLElement Object
                        (
                            [txtype] => Array
                                (
                                    [0] => SimpleXMLElement Object
                                        (
                                            [transactiontype] => Deferred
                                            [currencies] => SimpleXMLElement Object
                                                (
                                                    [currency] => SimpleXMLElement Object
                                                        (
                                                            [currencycode] => GBP
                                                            [totalnumber] => ##
                                                            [totalvalue] => £####.##  
                                                      )

                                                )

                                        )

                                    [1] => SimpleXMLElement Object
                                        (
                                            [transactiontype] => Refund
                                            [currencies] => SimpleXMLElement Object
                                                (
                                                    [currency] => SimpleXMLElement Object
                                                        (
                                                            [currencycode] => GBP
                                                            [totalnumber] => ##
                                                            [totalvalue] => £####.##
                                                        )

                                                )

                                        )

                                )

                        )

                )

        )

    [timestamp] => 08/02/2011 08:10:33
)
</pre>

Basically, I need to go through and extract the transactiontype, totalnumber and totalvalue for each occurance. Is this possible to automate?

Any Information would be greatly appreciated...

Thanks Guys!

Jay

Re: PHP XML Extraction

Posted: Tue Feb 08, 2011 3:18 am
by Zyxist
Why do you use the internal structure of SimpleXMLElement object? Extracting the data from them is clearly described in the PHP manual:

http://docs.php.net/manual/en/simplexml ... -basic.php

It contains everything you need.