Last active
May 2, 2018 07:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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