Location: PHPKode > scripts > class_xmlparser > class_xmlparser/class_xmlparser.php
<?php
/****************************************************************
*****************************************************************

class_log.php: create to work with log file (create and search).
Copyright (C) 2003  Matthieu MARY hide@address.com

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

You can found more information about GPL licence at:
http://www.gnu.org/licenses/gpl.html

for contact me: hide@address.com
****************************************************************
****************************************************************/
/**
 * latest version can be download at http://www.phpclasses.org/browse.html/package/1236.html
 *
 * create the : july 19th 2003.
 * @author      Matthieu MARY &lt;<a href="mailto:hide@address.com">hide@address.com</a>&gt;
 * @version     1.0.0
 */
 
/**
* @shortdesc check xml tags
**/
  class xmlparser{
   /**
    * the list of errors
    * @type array
    * @private
    **/
    var $aErrors;			
   /**
    * the file to analyse
    * @type string
    * @private
    **/
    var $sFile;
   /**
    * the xml parser
    * @type mixed
    * @private
    **/
    var $xmlparser;
   /**
    * the data read
    * @type string
    * @private
    **/
    var $sData;

   /**
    * builder
    *
    * @param string sFile required. the path to file to analyse
    * @type void
    * @public
    **/
    function xmlparser($sFile)
    {
             $this->aErrors = array();
             $this->sFile = $sFile;
             $this->xmlparser =  null;
             $this->sData = "";

             if (!is_file($this->sFile)){
                  $this->aErrors[] = "file [".$this->sFile."] is not a valid file";
                  return;
             }

             // ouverture du fichier en lecture
             if (!($fpxml=fopen($this->sFile,"r"))){
                   $this->aErrors[] = "unable to open [".$this->sFile."] in reading";
                   return;
             }
             
             // cree un objet parser xml
             $this->xmlparser = xml_parser_create();

             // exploitation des données
             while($this->sData = fread($fpxml,4096)){
                  // analyse des données lues
                  if (!(xml_parse($this->xmlparser,$this->sData,feof($fpxml)))){
                  // il s'est produit une erreur
                     $this->aErrors[] = "file [".$this->sFile."] - XML error: ".xml_error_string(xml_get_error_code($this->xmlparser))." line ". xml_get_current_line_number($this->xmlparser);
                     $this->aErrors[] = "line ".xml_get_current_line_number($this->xmlparser).":[".$this->sData."]";
                     break;
                  }
             }
             fclose($fpxml);
             $this->end();
    }// constructeur

   /**
    * return the errors
    *
    * @type array
    * @public
    **/
    function get_errors()
    {
     return $this->aErrors;
    }

   /**
    * return if there is an error
    *
    * @type int
    * @public
    **/
    function is_errors()
    {
     return count($this->aErrors);
    }

   /**
    * free
    *
    * @type void
    * @private
    **/
    function end()
    {
       xml_parser_free($this->xmlparser);
       return;
    }
}
?>
Return current item: class_xmlparser