I had many issues to dealing with while solving this problem i i though about sharing this. The code below illustates a simple logis to create a XML file if it is not present and create a root node. And looking at this node you can create chile nodes.
The code is as follows:-
<?php
$uvar = "HELLO";
$doc = new DOMDocument('1.0', 'UTF-8');
$ele = $doc->createElement( 'root' );
$ele->nodeValue = $uvar;
$doc->appendChild( $ele );
$test = $doc->save("file.xml")
?>
This will create a file.xml with the following contents:-
<?xml version="1.0" encoding="UTF-8"?>
<root>HELLO</root>
The code is as follows:-
<?php
$uvar = "HELLO";
$doc = new DOMDocument('1.0', 'UTF-8');
$ele = $doc->createElement( 'root' );
$ele->nodeValue = $uvar;
$doc->appendChild( $ele );
$test = $doc->save("file.xml")
?>
This will create a file.xml with the following contents:-
<?xml version="1.0" encoding="UTF-8"?>
<root>HELLO</root>
Comments
Post a Comment