使用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>

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

Try using PHP's SimpleXML

The SimpleXML usage page gives a good tutorial of how to use it.

This should do the trick:

$xml_load = simplexml_load_file($Your_xml);
$song = $xml_load->addChild("song");
$song->addChild("title", "song title");
$song->addChild("album", "song album");
$song->addChild("artist", "song artist");
$song->addChild("length", "03:01");

echo $xml_load->saveXML()