doujiong2533 2015-02-11 06:02
浏览 37

使用php将数组转换为xml

I have a multi-dimensional array. the array was carefully built from my xml structure. here's it with var_dump

array (size=1)
  'Articles' => 
    array (size=4)
      '@About' => string 'programming' (length=11)
      '@compile' => string 'pro' (length=3)
      'Article' => 
        array (size=3)
          0 => 
            array (size=6)
              ...
          1 => 
            array (size=6)
              ...
          2 => 
            array (size=6)
              ...
      '$' => string 'Idiot ! How to programme' (length=24)

and here's it with print_r()

the return of print_r() :
Array ( 
        [Articles] => Array ( 
                      [@About] => programming 
                      [@compile] => pro 
         [Article] => Array 
                 ( 
                      [0] => Array 
                      ( 
                           [@ID] => 111 
                           [@Lang] => C++ 
                           [title] => Array ( 
                                 [@HELP] => Needed 
                           [$] => C++ is my boss 
                       ) 
                          [author] => Idiotic Me 
                          [summary] => if you dont like Cpp, your a Moron 
                          [$] => Best Language ) 
                       [1] => Array 
                       ( 
                          [@ID] => 222 
                          [@Lang] => Json 
                          [title] => 
                       Array 
                       ( 
                          [ox] => Array ( ) 
                          [$] => Json is a fool 
                       ) 
                          [author] => who cares ! 
                          [summary] => I detest json 
                          [$] => Or whatever it calls itself 
                        ) 
                        [2] => Array
                        ( 
                           [@ID] => 333 
                           [@Lang] => Ruby 
                           [title] => A rival of Cpp 
                           [author] => intersting to know 
                           [summary] => a good language i think 
                           [$] => Hottest in town 
                         ) 
                  ) 
                   [$] => Idiot ! How to programme 
                )
 ) 
Note that all attribute names were mapped against the '@' sign and node contents against the '$' sign. apparently, here's the xml data from where the above array was obtained :

now here's the xml structur from which the above array was obtained :

<?xml version="1.0"?>
<Articles About="programming" compile="pro"> 
    Idiot ! How to programme
    <Article ID="111" Lang= "C++"> 
        Best Language
        <title HELP="Needed">C++ is my boss</title>
        <author>Idiotic Me</author> 
        <summary>if you dont like Cpp, your a Moron </summary> 
    </Article>
    <Article ID="222" Lang="Json">
     Or whatever it calls itself
        <title> Json is a fool
              <sub> just a test </sub>
        </title>
        <author> who cares !</author> 
        <summary> I detest json </summary> 
    </Article> 
    <Article ID="333" Lang="Ruby">
     Hottest in town
        <title> A rival of Cpp</title>
        <author> intersting to know</author> 
        <summary> a good language i think </summary>  
    </Article>    
</Articles>

i am finding it painful to convert the above array back into its exact xml form. any solution to that thanks in advance !

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波
    • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
    • ¥15 钢筋实图交点识别,机器视觉代码
    • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
    • ¥50 400g qsfp 光模块iphy方案
    • ¥15 两块ADC0804用proteus仿真时,出现异常
    • ¥15 关于风控系统,如何去选择