I would like to add an element node in my XML file using PHP. I can not get it right when I add it below root.
Please show me some clean code so that I understand how it works. Thank you!
My xml is
<?xml version="1.0" encoding="utf-8"?>
<GameStore>
<Game type="adventure">
<TITLE>Assassin's Creed: Brotherhood</TITLE>
<PUBLISHER>Ubisoft</PUBLISHER>
</Game>
<Game type="adventure">
<TITLE>Batman: Arkham Asylum</TITLE>
<PUBLISHER>Eidos</PUBLISHER>
</Game>
</GameStore>
If you want to add a new game element, simplexml handles this pretty convenient. Example ($data is obviously your xml):
This will append a “game” child to your xml. We then append two children (title, publisher) to game.