duanpaotian2348 2015-07-18 18:12
浏览 23
已采纳

使用PHP将数据添加到XML文件

I would like to add some data to a XML file using PHP. I'm quite new and so do not know much of the terminology and so will try to explain it as much as possible. Thanks Joe

XML FILE:

<?xml version="1.0" encoding="UTF-8"?>
<music>
    <song>
        <title>Example Song</title>
        <album>A Album</album>
        <artist>A Artist</artist>
        <length>3.41</length>
    </song>
//The New Song I Would Like To Add For Example
    <song>
        <title>Another Example Song</title>
        <album>Another A Album</album>
        <artist>Another A Artist</artist>
        <length>Another 3.41</length>
    </song>
//The End Of The New Song I Would Like To Add

</music>
  • 写回答

3条回答 默认 最新

  • ds78662302 2015-07-18 18:38
    关注

    I haven't tested that but I think that it would be work

    With SimpleXML

    // Read file    
    $music = simplexml_load_file('music.xml');
    
    $character = $music->addChild('song');
    $character->addChild('title', 'Another Example Song');
    $character->addChild('album', 'Another A Album');
    $character->addChild('artist', 'Another A Artist');
    $character->addChild('length', 'Another 3.41');
    

    And then force download the new file

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划