XML Parsing (XML to Table)

Written by @m_k_amin 20 November 2012

This is a simple script to parse an XML file. It reads data from the file and insert them into table. the left column of the table is XML tags and the right one is their values. A sample XML is in attachment.

Code Snippet:

                                                
                                                <!-- this script is provided by www.phpfreecode.com coded by: Kerixa Inc. -->
<!-- This Script is from www.phpfreecpde.com, Coded by: Kerixa Inc-->
<table align="center" style="width: 458px; font-family: 'Times New Roman', Times, serif; height: 87px; border-width: 0px">
<?php
$xmlfile = 'test.xml';
$xmlparser = xml_parser_create();
$fp = fopen($xmlfile, 'r');
$xmldata = fread($fp, 4096);
xml_parse_into_struct($xmlparser,$xmldata,$values);
xml_parser_free($xmlparser);

foreach($values as $m){
	if ($m['type']=='open'||$m['type']=='complete' ){
		  echo('<tr style="background-color: #8BD4FF"><td style="text-align: left; width: 228px; font-size: 17pt; height: 29px; background-color: #CECEFF;">
		<strong>'.$m['tag'].'</strong></td>
		<td style="text-align: left; width: 228px; font-size: 17pt; height: 29px; background-color: #CECEFF;">'.$m['value'].
		'</td></tr>');

	}
}
?>
</table>
<div style="text-align: center">
	<font face="Tahoma"><a target="_blank" href="http://www.phpfreecode.com/">
	<span style="font-size: 8pt; text-decoration: none">PHP Free Code
</span></a></font></div><a target='_blank' href='www.phpfreecode.com' style='font-size: 8pt; text-decoration: none'>Php Best Codes</a>                                                
                                            

Example:


About @m_k_amin

This user is pending a biography.

M
TRENDING POST
1
2
3
4
5
VISITORS
Online Users: 12
Recent Members: Manaakividuinfo.com, karticksv, sava, tinatina, sandiegostrippersinsandiego
advertisement 2