phpDocumentor lodel
[ class tree: lodel ] [ index: lodel ] [ all elements ]

Source for file checkxml.php

Documentation is available at checkxml.php

  1. <?php
  2. /**
  3.  * Fichier proposant des fonctions pour valider le XML Lodel
  4.  *
  5.  * PHP versions 4 et 5
  6.  *
  7.  * LODEL - Logiciel d'Edition ELectronique.
  8.  *
  9.  * Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
  10.  * Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  11.  * Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  12.  * Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  13.  * Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  14.  * Copyright (c) 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  15.  *
  16.  * Home page: http://www.lodel.org
  17.  *
  18.  * E-Mail: lodel@lodel.org
  19.  *
  20.  * All Rights Reserved
  21.  *
  22.  * This program is free software; you can redistribute it and/or modify
  23.  * it under the terms of the GNU General Public License as published by
  24.  * the Free Software Foundation; either version 2 of the License, or
  25.  * (at your option) any later version.
  26.  *
  27.  * This program is distributed in the hope that it will be useful,
  28.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  30.  * GNU General Public License for more details.
  31.  *
  32.  * You should have received a copy of the GNU General Public License
  33.  * along with this program; if not, write to the Free Software
  34.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  35.  *
  36.  * @author Ghislain Picard
  37.  * @author Jean Lamy
  38.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  39.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  40.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  41.  * @licence http://www.gnu.org/copyleft/gpl.html
  42.  * @version CVS:$Id:
  43.  * @package lodel
  44.  */
  45.  
  46. /**
  47.  * Vérifie le contenu d'un fichier.
  48.  *
  49.  * Cette méthode récupère le contenu d'un fichier et appelle la méthode checkstring
  50.  *
  51.  * @param string $filename le nom du fichier
  52.  * @param integer $error (n'est pas utilisé dans la fonction) par défaut à 0
  53.  * @return un booleen indiquant si le XML est valide ou non.
  54.  */
  55. function checkfile($filename$error 0)
  56. {
  57.     $text file($filename);
  58.     return checkstring($text);
  59. }
  60.  
  61. /**
  62.  * Vérifie le XML d'une chaine de caractère
  63.  *
  64.  * @param string &$text la chaine de caractère
  65.  * @param integer $error (n'est pas utilisé dans la fonction) par défaut à 0
  66.  * @return un booleen indiquant si le XML est valide ou non.
  67.  */
  68. function checkstring(&$text$error 0)
  69. {
  70.     $xml_parser xml_parser_create();
  71.     xml_parser_set_option($xml_parserXML_OPTION_CASE_FOLDING0or die("Parser incorrect");
  72.     if ($error)    {
  73.         xml_set_element_handler($xml_parser"startElementCHECK""endElementCHECK");
  74.         xml_set_character_data_handler($xml_parser"characterHandlerCHECK");
  75.     }
  76.  
  77.     if (!xml_parse($xml_parser$text))    {
  78.         if (!$error{
  79.             echo '<h1>ERROR</h1><p>Le fichier produit n\'est pas XML. Veuillez svp poster un rapport de bug sur <a href="http://sourceforge.net/projects/lodel/">http://sourceforge.net/projects/lodel<a/>. Pensez &agrave; joindre le fichier.<br />En attendant que le problème soit résolu, essayez de changer le stylage de votre fichier.</p><p><hr /></p>';
  80.  
  81.             require $GLOBALS[home]."xmlfunc.php";
  82.             $text indentXML($text);
  83.             checkstring($text1);
  84.             return;
  85.         else {
  86.             echo "<font color=red>";
  87.             echo preg_replace("/\n/se""'<br /><b>'.((\$GLOBALS[line]++)+2).'</b> '"htmlspecialchars(substr($textxml_get_current_byte_index($xml_parser2)));
  88.             echo "</font>\n";
  89.             echo sprintf("<br /><H2>XML error: %s ligne %d</H2>"xml_error_string(xml_get_error_code($xml_parser))xml_get_current_line_number($xml_parser));
  90.             echo "L'erreur se situe avant la zone rouge. Elle peut etre due a une erreur bien au dessus la ligne donne par le parser<br />";
  91.             echo "<br />".htmlentities($text);
  92.  
  93.             xml_parser_free($xml_parser);
  94.             return FALSE;
  95.         }
  96.     }
  97.     xml_parser_free($xml_parser);
  98.     return TRUE;
  99. }
  100.  
  101. /**
  102.  *
  103.  *
  104.  *
  105.  */
  106. function characterHandlerCHECK($parser$data)
  107. {
  108.     echo preg_replace("/\n/se""'<br /><b>'.((\$GLOBALS[line]++)+2).'</b> '"$data);
  109. }
  110.  
  111.  
  112. /**
  113.  *
  114.  *
  115.  *
  116.  */
  117. function startElementCHECK($parser$name$attrs)
  118. {
  119.     $balise "<$name";
  120.     foreach ($attrs as $att => $val{
  121.         $balise .= " $att=\"$val\"";
  122.     }
  123.     $balise .= ">";
  124.  
  125.     echo "<font color=blue>"htmlentities($balise)"</font>";
  126. }
  127.  
  128. /**
  129.  *
  130.  *
  131.  *
  132.  */
  133. function endElementCHECK($parser$name)
  134. {
  135.     echo "<font color=blue>&lt;/$name&gt;</font>";
  136. }
  137. ?>

Documentation generated on Thu, 24 Jul 2008 05:07:17 +0200 by phpDocumentor 1.4.0a2