PHP Classes
Icontem

File: example.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Mikael Göransson  >  Recursive array to XML  >  example.php  
File: example.php
Role: Example script
Content type: text/plain
Description: A short example of what the class is meant to do
Class: Recursive array to XML
Generate XML documents from nested arrays
 

Contents

Class file image Download
<?php
// Include the class (using require_once just for good measure)
require_once('xml.php');

// This is just dummy data to show what the class does
$exampleData = array(
                    
'root' => array(
                                
'foobar' => 'foovalue',
                                
'flump' => array('doh'),
                                
'hedk option="something"' => array(
                                                                
'gnu'   => 'gnu is not unix',
                                                                
'linux' => 'linux is gnu'
                                                            
),
                                
'1plutt' => 'To create multiple tags with the same name, start with a number',
                                
'2plutt' => 'This is the second tag with the same name, but in the array it\'s starting with a different number',
                                
'numeric' => 'Numeric values are not valid in XML tags, so we treat them as unassociated arrays, creating a tag of the value.',
                                
'1' => 'numeric_tag',
                                
=> 'another_numeric_tag',
                            ),
                );

// Initiate the class
$xml = new xml();

// Set the array so the class knows what to create the XML from
$xml->setArray($exampleData);

// Print the XML to screen
$xml->outputXML('echo');
/**
 * This will create:
 * <?xml version="1.0" encoding="ISO-8859-1"?>
 * <root>
 *     <foobar>foovalue</foobar>
 *     <flump>
 *         <doh />
 *     </flump>
 *     <hedk option="something">
 *         <gnu>gnu is not unix</gnu>
 *         <linux>linux is gnu</linux>
 *     </hedk>
 *     <plutt>To create multiple tags with the same name, start with a number</plutt>
 *     <plutt>This is the second tag with the same name, but in the array it&apos;s starting with a different number</plutt>
 *     <numeric>Numeric values are not valid in XML tags, so we treat them as unassociated arrays, creating a tag of the value.</numeric>
 *     <numeric_tag />
 *     <another_numeric_tag />
 * </root>
 *
 */
?>

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products