2012-01-12 56 views
0

我想在CakePHP框架的XML類中使用toArray將XML更改爲數組。XML到CakePHP中的數組然後保存

下面是陣列輸出:

[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 
                       (

現在的問題是如何才能真正改變這個使我能得到我需要萃取,然後將那些拯救他們?

我需要@name,典型值,DOM,折扣,ACR等..

是使用核心庫類設置這個選項?如果是的話,你會推薦哪一個?

回答

0

嘗試這樣的事情,這是很容易得到的值保持:

 

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

希望它可以幫助

+0

其實我找到了答案!使用Set :: extract並使用xPath提取數據,然後從那裏創建數組! – 2012-01-12 11:30:07

相關問題