PHP Classes
elePHPant
Icontem

File: test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Claudio Castelpietra  >  VFXP_XML_Parser  >  test.php  >  Download  
File: test.php
Role: Example script
Content type: text/plain
Description: Example class usage
Class: VFXP_XML_Parser
Light XML parser optimized for speed. Pure PHP.
Author: By
Last change:
Date: 9 years ago
Size: 1,263 bytes
 

Contents

Class file image Download
<?php

   
require_once('VFXP.inc.php');
   
   
$xmldoc =& new VFXP_Document();
   
$xmldoc->parseFromFile('test.xml');
   
   
$rootelem =& $xmldoc->rootElement();
   
   
    function
spaces($n) {
       
$out = '';
        for (
$p = 0; $p < $n; ++$p) {
           
$out .= ' ';
        }
        return
$out;
    }
    function
recursive_print(&$element, $level = 0) {
       
$out = '';
       
$out .= spaces($level*8) . 'Begin Element' . "\n";
       
$out .= spaces($level*8) . '-------Name: ' . $element->name() . "\n";
       
$out .= spaces($level*8) . '------Value: ' . $element->value() . "\n";
       
$out .= spaces($level*8) . '-Attributes: ' . "\n";
        foreach (
$element->attributes() as $key => $val) {
           
$out .= spaces($level*8+8) . "[{$key}] => $val" . "\n";
        }
       
$out .= spaces($level*8) . '---Children: ' . "\n";
        foreach (
$element->children() as $child) {
           
$out .= recursive_print($child, $level + 1);
        }
       
$out .= spaces($level*8) . 'End Element' . "\n";
        return
$out;
    }
   
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>VFXP Test</title>
</head>

<body>

<pre>
<?php

//print_r($rootelem);

echo recursive_print($rootelem);

?>
</pre>

</body>
</html>