Skip to content

Instantly share code, notes, and snippets.

@iampava
Last active May 2, 2018 07:19
Show Gist options
  • Save iampava/815e39aaa04c11609f5be54ff5a01098 to your computer and use it in GitHub Desktop.
Save iampava/815e39aaa04c11609f5be54ff5a01098 to your computer and use it in GitHub Desktop.
Creating an XML file from PHP using DOM | Author: Răzvan Sbîngu
<?php
$domtree = new DOMDocument('1.0', 'UTF-8');
$xmlRoot = $domtree -> createElement("books");
$book = $domtree -> createElement("book");
$book -> appendChild( $domtree -> createElement("title", "Harry Potter") );
$book -> appendChild( $domtree -> createElement("description", "Best book") );
$book -> setAttribute("class", "gallery");
$xmlRoot -> appendChild($book);
$domtree -> appendChild($xmlRoot);
echo $domtree -> saveXML();
?>
<!-- <books>
<book>
<title> Harruy </title>
<description> sadasd </description>
</book>
</books> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment