I used the linked post to try out generating some XML in PHP, but in the browser when it echos the XML, it's just a string, with no structure. What am I doing wrong? https://stackoverflow.com/a/487629/2702121
Here's an image of the output:
Here's the code in my PHP file:
/* create a dom document with encoding utf8 */
$domtree = new DOMDocument('0.9', 'UTF-8');
/* create the root element of the xml tree */
$xmlRoot = $domtree->createElement("xml");
/* append it to the document created */
$xmlRoot = $domtree->appendChild($xmlRoot);
$currentTrack = $domtree->createElement("track");
$currentTrack = $xmlRoot->appendChild($currentTrack);
/* you should enclose the following two lines in a cicle */
$currentTrack->appendChild($domtree->createElement('path','song1.mp3'));
$currentTrack->appendChild($domtree->createElement('track_title','title of song1.mp3'));
$currentTrack->appendChild($domtree->createElement('path','song2.mp3'));
$currentTrack->appendChild($domtree->createElement('track_title','title of song2.mp3'));
/* get the xml printed */
echo $domtree->saveXML();