Login   Register  
PHP Classes
elePHPant
Icontem

File: demo.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Rabotyahoff Alexandr  >  c_xml  >  demo.php  >  Download  
File: demo.php
Role: Example script
Content type: text/plain
Description: demo script
Class: c_xml
Convert between XML files and arrays or strings
Author: By
Last change:
Date: 2 years ago
Size: 981 bytes
 

Contents

Class file image Download
<?php

include_once 'c_xml.php';

echo 
'<html>';

$xml=file_get_contents('demo.xml');
echo 
"input xml<br><textarea rows='10' cols='100'>$xml</textarea><br><br>";

/*1. show xml-dump*/
echo "xml-dump:<br>";
echo 
c_xml::dump($xml,true);
echo 
"<br><br>";

/*2. convert xml to array*/
$o_xml=new c_xml($xml);
$array=$o_xml->toArray(array('bike'));
echo 
"xml to array<br><textarea rows='10' cols='100'>";
print_r($array);
echo 
"</textarea><br><br>";

/*3. change array. Convert array to xml*/
foreach ($array as $key=>$item){
    if (
c_xml::is_system_key($key)) continue;
    
$array[$key]['@year']=2011;
    
$array[$key]['owner']['.']='Koreyko';
}
$o_new_xml=new c_xml_node();
$o_new_xml->fromArray('new_bikes',$array);
$new_xml=$o_new_xml->toXML();
echo 
"new xml<br><textarea rows='10' cols='100'>$new_xml</textarea><br><br>";

/*4. xml*xsl processing*/
echo "xsl-processing:<br>";
echo 
xsl_out('demo.xsl','data',$array);
echo 
"<br><br>";


echo 
'</html>';