PHP XML Extraction

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Cisco-come-Developer
Forum Newbie
Posts: 1
Joined: Tue Feb 08, 2011 2:18 am

PHP XML Extraction

Post 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
User avatar
Zyxist
Forum Contributor
Posts: 104
Joined: Sun Jan 14, 2007 10:44 am
Location: Cracow, Poland

Re: PHP XML Extraction

Post 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.
Post Reply