XML in PHP Example

(Last Updated On: August 11, 2016)

Nowadays all the information’s are communicated as JSON or XML. We have already seen how to write the JSON file. Now we will see how to write the XML file,

<?php
$xom = xmlwriter_open_memory();
$place = 'Arcot';
$pincode = '632503';
xmlwriter_start_document($xom,'1.0','UTF-8');
xmlwriter_start_dtd($xom,'html','-//WAPFORUM//DTD XHTML Mobile 1.0//EN', 'http://www.wapforum.org/DTD/xhtml-mobile10.dtd');
xmlwriter_end_dtd($xom);
xmlwriter_start_element($xom,'Area');

xmlwriter_write_element ($xom,'Place', $place);
xmlwriter_write_element ($xom,'Pincode', $pincode);
xmlwriter_end_element($xom);

xmlwriter_end_dtd($xom);
$xml = xmlwriter_output_memory($xom,true);
echo $xml;
?>

Output:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<Area>
<Place>Arcot</Place>
<Pincode>632503</Pincode>
</Area>

Recommended PHP Books:

Please feel free to share your comments……

275 total views, 0 views today

Leave a Reply

Your email address will not be published. Required fields are marked *