Site PHP+MySQL Evénementiel

crabs_web_event-2.0 ©2005-2006 - Christophe CAZAJUS (crabs-mettre_le_signe_at-crabs-world.com)

~~ / ADMIN / CLASS / xml.php
Makefile xml.php style.php
    1 <?php
    2 //
    3 // =============================================================================
    4 //  crabs_web_event-2.0 : Site PHP+MySQL Evénementiel
    5 //  Copyright (C) 2005-2006 : Christophe CAZAJUS (crabs-mettre_le_signe_at-crabs-world.com)
    6 //
    7 //  Ce source fait partie d'un projet logiciel libre. Vous pouvez le distribuer
    8 //  et/ou le modifier en respectant les termes de la GNU General Public License
    9 //  version 2 ou (suite a votre propre choix) une version ulterieure.
   10 //
   11 //  Ce programme est distribue dans l'espoir qu'il puisse etre utile, mais
   12 //  sans aucune garantie, meme si il est associe a un produit qui vous en
   13 //  propose une. Conformez-vous a la GNU General Public License pour avoir
   14 //  plus de precisions.
   15 //
   16 //  L'auteur ne peut etre tenu responsable de l'utilisation faite des
   17 //  composantes associees a ce projet (en partie ou dans leur totalite).
   18 //
   19 //  Une copie du fichier de la GNU GPL est fournie dans le repertoire DOC
   20 //  de ce projet sous le nom gnu_gpl.txt
   21 //
   22 // =============================================================================
   23 //
   24 class XML
   25     {
   26     var $racine     ;
   27     var $pere       ;
   28     var $fils       ;
   29     var $nom        ;
   30     var $text       ;
   31     var $text_empty ;
   32     var $attributs  ;
   33     var $simple     ;
   34     var $xsl        ;
   35 
   36     function XML( $pere=false)
   37         {
   38         if ( $pere )
   39             {
   40             $this->pere = $pere ;
   41             $this->racine = $pere->racine ;
   42             }
   43         else
   44             {
   45             $this->racine = $this ;
   46             $this->pere = false ;
   47             $this->nom = 'document' ;
   48             }
   49         $this->fils = false ;
   50         $this->text = false ;
   51         $this->text_empty = true ;
   52         }
   53 
   54     function &addElement( $nom, $attr=false )
   55         {
   56         if ( $this->simple ) return false ;
   57         $e = new XML( $this ) ;
   58         $e->nom = $nom ; $e->attributs = $attr ; $e->simple=false ;
   59         if ( $this->fils == false ) $this->fils = array() ;
   60         $this->fils[] = &$e ;
   61         return $e ;
   62         }
   63 
   64     function &addElementSimple( $nom, $attr=false )
   65         {
   66         if ( $this->simple ) return false ;
   67         $e = new XML( $this ) ;
   68         $e->nom = $nom ; $e->attributs = $attr ; $e->simple=true ;
   69         if ( $this->fils == false ) $this->fils = array() ;
   70         $this->fils[] = &$e ;
   71         return $e ;
   72         }
   73 
   74     function &addElementText( $nom, $txt, $attr=false )
   75         {
   76         if ( $this->simple ) return false ;
   77         $e = new XML( $this ) ;
   78         $e->nom = $nom ; $e->attributs = $attr ; $e->simple=false ;
   79         $e->text = "$txt" ; $e->text_empty = false ;
   80         if ( $this->fils == false ) $this->fils = array() ;
   81         $this->fils[] = &$e ;
   82         return $e ;
   83         }
   84 
   85     function affiche()
   86         {
   87         header( 'Content-type: text/xml' ) ;
   88         $nl = "\n" ;
   89         echo '<?xml version="1.0" encoding="iso-8859-15" ?>',$nl ;
   90         if ( $this->xsl )
   91             echo '<?xml-stylesheet type="text/xsl" href="',$this->xsl,
   92                 '" ?>',$nl;
   93         $this->afficheElement() ;
   94         }
   95     function afficheElement( $indent='' )
   96         {
   97         if ( $this->simple )
   98             { $end_tag = ' />' ; $close_tag = '' ; }
   99         else
  100             { $end_tag = '>' ; $close_tag = $indent."</".$this->nom.">\n" ; }
  101         echo $indent,'<',$this->nom ;
  102         if ( $this->attributs != false )
  103             foreach( $this->attributs as $var => $val )
  104                 echo ' ',$var,'="',$val,'"' ;
  105         if ( $this->text_empty == true )
  106             echo $end_tag,"\n" ;
  107         else
  108             { echo $end_tag,$this->text; $close_tag = "</".$this->nom.">\n"; }
  109         if ( $this->fils != false )
  110             foreach( $this->fils as $f ) $f->afficheElement( $indent."\t" ) ;
  111         echo $close_tag ;
  112         }
  113     }
  114 ?>
Makefile xml.php style.php
~~ / ADMIN / CLASS / xml.php

Haut de page

Contacter crabs

Date de génération : 22/09/2011 21:48