Skip to content Skip to sidebar Skip to footer

PHP Creating XML file

Reading Time: < 1 minute

How to creating simple xml file using php.I’ll describes how to creating xml file by formatting tags using php.

createElement("Student"); // creating  opening root tag
	// Process  tag
	$xml_name = $xml->createElement("Name"); // creating  opening tag
	$xml_name->nodeValue = 'John doe'; // add value to the  element
	$xml_student->appendChild($xml_name); // creating  closing tag
	// Process  tag
	$xml_country = $xml->createElement("Country"); // creating  opening tag
	$xml_country->nodeValue = 'US'; // add value to the  element
	$xml_student->appendChild($xml_country); // creating  closing tag
	// Process  tag
	$xml_email = $xml->createElement("Email"); // creating  opening tag
	$xml_email->nodeValue = '[email protected]'; // add value to the  element
	$xml_student->appendChild($xml_email); // creating  closing tag
	$xml->appendChild($xml_student); // creating  closing root tag
	$xml->formatOutput = true; // formatting tags
	$xml->save("Students.xml"); // Save the file named "Student.xml"
?>

That’s all.
Download PHP Creating XML file Example(2 KB)