Array to XML Class Example

Including

Include class.ArrayToXML.php on the page where you want to convert an array to XML.

				include("class.ArrayToXML.php");
			

Example

Your PHP code
/* Sample Code */
$sample = Array
(
	0 => Array
		(
			'Item' => Array
				(
					'id' => 1,
					'title john="doe"' => 'The title',
					'body' => 'This is my body.',
					'created' => '2013-03-28 10:00:06',
					'modified' => '2013-03-28 13:20:29',
					'rating' => '10',
				)
		),
	1 => Array
		(
			'Item' => Array
				(
					'id' => 2,
					'title' => 'Lorem Ipsum',
					'body' => 'Lorem ipsum is just a simple sample text.',
					'created' => '2013-03-28 10:00:06',
					'modified' => '2013-03-28 13:20:29',
					'rating' => '7',
					array('John Doe'),
				)
		),
	2 => Array
		(
			'Item' => Array
				(
					'id' => 3,
					'title' => 'CodeCanyon',
					'body' => 'CodeCanyon is really useful',
					'created' => '2013-03-28 10:00:06',
					'modified' => '2013-03-28 13:20:29',
					'rating' => '9',
				)
		),
);



header ("content-type: text/xml");
include ('class.ArrayToXML.php');
$xml = new ArrayToXML($sample);
echo $xml->to_xml();
			
This outputs the following XML code
<?xml version="1.0" encoding="iso-8859-1"?>

	
		
			1
			The title
			<body>This is my body.</body>
			2013-03-28 10:00:06
			2013-03-28 13:20:29
			10
		
	
	
		
			2
			Lorem Ipsum
			<body>Lorem ipsum is just a simple sample text.</body>
			2013-03-28 10:00:06
			2013-03-28 13:20:29
			7
			
				John doe
			
		
	
	
		
			3
			CodeCanyon
			<body>CodeCanyon is really useful</body>
			2013-03-28 10:00:06
			2013-03-28 13:20:29
			9