hellonoko Posted November 19, 2008 Share Posted November 19, 2008 I am trying to build a XML document like this one dynamically: <?xml version="1.0" encoding="UTF-8"?> <playlist version="1" xmlns="http://xspf.org/ns/0/"> <trackList> <track><location>file:///mp3s/song_1.mp3</location></track> <track><location>file:///mp3s/song_2.mp3</location></track> <track><location>file:///mp3s/song_3.mp3</location></track> </trackList> </playlist> My code so far: <?php // create doctype $dom = new DOMDocument("1.0"); // display document in browser as plain text // for readability purposes header("Content-Type: text/plain"); // create root element $root = $dom->createElement("playlist"); $dom->appendChild($root); // create child element $item = $dom->createElement("track"); $root->appendChild($item); // create text node $item = $dom->createElement("location"); $root->appendChild($item); // save and display tree $dom->save("playlist.xml"); ?> For some reason the createElement location tag is not working. But I am very new to XML so I am not sure what I am doing. Thanks, ian Link to comment https://forums.phpfreaks.com/topic/133404-building-a-xml-document-with-php/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.