0
votes

I'm trying to change XML to array using toArray in XML class in Cakephp framework.

Below is the array output:

 [state] => Array
                        (
                            [0] => Array
                                (
                                    [@code] => ACT
                                    [post_code] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [@code] => 2600
                                                    [locality] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [@name] => DEAKIN
                                                                    [dwelling_type] => Array
                                                                        (
                                                                            [@code] => H
                                                                            [typical_value] => Array
                                                                                (
                                                                                    [@rank] => 3341/3697
                                                                                    [@] => 831000
                                                                                )

                                                                            [dom] => Array
                                                                                (
                                                                                    [@score] => 1
                                                                                    [@rank] => 454/5673
                                                                                    [@] => 56
                                                                                )

                                                                            [discount] => Array
                                                                                (
                                                                                    [@score] => 0
                                                                                    [@rank] => 779/5673
                                                                                    [@] => 5%
                                                                                )

                                                                            [acr] => Array
                                                                                (
                                                                                    [@score] => -1
                                                                                    [@rank] => 914/5531
                                                                                    [@] => 59%
                                                                                )

                                                                            [renters] => Array
                                                                                (
                                                                                    [@score] => 0
                                                                                    [@rank] => 5131/5627
                                                                                    [@] => 42%
                                                                                )

                                                                            [vacancy] => Array
                                                                                (
                                                                                    [@score] => 1
                                                                                    [@rank] => 4714/5673
                                                                                    [@] => 2.61%
                                                                                )

                                                                            [yield] => Array
                                                                                (
                                                                                    [@score] => -1
                                                                                    [@rank] => 678/3697
                                                                                    [@] => 3.69%
                                                                                )

                                                                            [som] => Array
                                                                                (
                                                                                    [@score] => 1
                                                                                    [@rank] => 3915/5144
                                                                                    [@] => 2.08%
                                                                                )

                                                                            [search_dsr] => Array
                                                                                (
                                                                                    [@score] => -3
                                                                                    [@rank] => 3578/4009
                                                                                    [@] => 4.9
                                                                                )

                                                                            [dsr] => Array
                                                                                (
                                                                                    [@rank] => 3121/5673
                                                                                    [@] => 23
                                                                                )

                                                                            [sr] => Array
                                                                                (
                                                                                    [@rank] => 2552/5673
                                                                                    [@] => 5.8
                                                                                )

                                                                        )

                                                                )

                                                            [1] => Array
                                                                (
                                                                    [@name] => YARRALUMLA
                                                                    [dwelling_type] => Array
                                                                        (
                                                                            [0] => Array
                                                                                (

Now the problem is how can we actually transform this so that I can get the ones I need extracted then save them?

I need @name, typical value, dom, discount, acr etc...

Is using core library class Set an option for this? If so which one would you recommend?

1

1 Answers

0
votes

Try something like this, it's much easier to get hold of value:


$objXml = $yourXmlData;
$arrXml = Set::reverse($objXml); 
debug($arrXml);

Hope it helps