Skip to content

Instantly share code, notes, and snippets.

@GoodChancer
Created March 1, 2017 23:19
Show Gist options
  • Select an option

  • Save GoodChancer/ea80c597da9b16cf52f6b5a6d6767472 to your computer and use it in GitHub Desktop.

Select an option

Save GoodChancer/ea80c597da9b16cf52f6b5a6d6767472 to your computer and use it in GitHub Desktop.
<?php
//for temporarily displaying raw XML on php page
header('Content-Type: text/xml');
/* create a dom document with encoding utf8 */
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = true;
$plist = $doc->createElement('plist');
$plist = $doc->appendChild($plist);
$plist->setAttribute('version','1.0');
$dict = $doc->createElement('dict');
$plist->appendChild($dict);
$dict->appendChild($doc->createElement('key','Major Version'));
$dict->appendChild($doc->createElement('integer','1'));
$dict->appendChild($doc->createElement('key','Minor Version'));
$dict->appendChild($doc->createElement('integer','1'));
$dict->appendChild($doc->createElement('key','Date'));
$dict->appendChild($doc->createElement('date','2017-02-17T22:37:56Z'));
$dict->appendChild($doc->createElement('key','Features'));
$dict->appendChild($doc->createElement('integer','5'));
$dict->appendChild($doc->createElement('key','Tracks'));
$dict2 = $doc->createElement('dict');
$dict->appendChild($dict2);
$dict2->appendChild($doc->createElement('key','1'));
$dict3 = $doc->createElement('dict');
$dict2->appendChild($dict3);
$dict3->appendChild($doc->createElement('key','Track ID'));
$dict3->appendChild($doc->createElement('integer','1'));
$dict3->appendChild($doc->createElement('key','Name'));
$dict3->appendChild($doc->createElement('string','King and Cross'));
$dict3->appendChild($doc->createElement('key','Artist'));
$dict3->appendChild($doc->createElement('string','Ásgeir'));
$dict3->appendChild($doc->createElement('key','Album'));
$dict3->appendChild($doc->createElement('string','In the Silence (Deluxe Edition)'));
$dict3->appendChild($doc->createElement('key','Track Type'));
$dict3->appendChild($doc->createElement('string','Remote'));
$dict3->appendChild($doc->createElement('key','Apple Music'));
$dict->appendChild($doc->createElement('key','Playlists'));
$arrayElem = $doc->createElement('array');
$dict->appendChild($arrayElem);
$dict2 = $doc->createElement('dict');
$arrayElem->appendChild($dict2);
$dict2->appendChild($doc->createElement('key','Name'));
$dict2->appendChild($doc->createElement('string','My Great Playlist'));
$dict2->appendChild($doc->createElement('key','Description'));
$dict2->appendChild($doc->createElement('string','Description of this great playlist.'));
$dict2->appendChild($doc->createElement('key','All Items'));
$dict2->appendChild($doc->createElement('key','Playlist Items'));
$arrayElem2 = $doc->createElement('array');
$dict2->appendChild($arrayElem2);
$arrayElem2->appendChild($dict3);
$dict3->appendChild($doc->createElement('key','Track ID'));
$dict3->appendChild($doc->createElement('integer','1'));
/* get the xml saved and printed */
$doc->save('xml/test2.xml');
echo $doc->saveXML();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment