PHP Classes
Icontem

File: plugins/DrevoXMLParser.class.php


  Search   All class groups All class groups   Latest entries Latest entries   Top 10 charts Top 10 charts   Newsletter Newsletter   Blog Blog   Forums Forums   Help FAQ Help FAQ  
  Login   Register  
Recommend this page to a friend! ReTweet ReTweet Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Alexander Skakunov  >  Drevo Export  >  plugins/DrevoXMLParser.class.php  
File: plugins/DrevoXMLParser.class.php
Role: Class source
Content type: text/plain
Description: Drevo data file parser
Class: Drevo Export
Export event dates from Drevo to Google Calendar
 

Contents

Class file image Download
<?
/*
- author: Skakunov Alexander [i1t2b3@gmail.com]
- filename: FuseBoxXMLParser.class.DrevoXMLParser
- date: 04.05.08
- description: DrevoXMLParser parses an XML imported from Genery software Drevo application and creates a convenient PHP array of persons in it
*/

class DrevoXMLParser
{
  
protected $arr_persons;
  
protected $oXML;
  
  
public function DrevoXMLParser($xml)
  {
    
//new dBug( $xml, 'xml');
    
if( !function_exists('simplexml_load_string') )
    {
      
throw new Exception('No SimpleXML package available. Please add its support.');
    }
    
$this->arr_persons = array();
    
$this->oXML simplexml_load_string($xml);
    if(
false === $this->oXML)
    {
      
throw new Exception('Cannot parse XML provided. Check your data.');
    }
    
$this->process_xml();
    
//new dBug( $this->arr_persons);
  
}
  
  
protected function process_xml()
  {
    foreach( 
$this->oXML->Pers->as $person)
    {
      
$id = (string)$person['id'];
      
$fields = array( 'bfdate''dfdate''fn''mn''sn''fullname''lifespan''sex' );
      foreach( 
$fields as $field )
      {
        
$this->arr_persons$id ][$field] = (string)$person->{$field}; //arr[id]=data
      
}
      
$this->clean_date$this->arr_persons$id ]['bfdate'] );
      
$this->clean_date$this->arr_persons$id ]['dfdate'] );
      if( empty( 
$this->arr_persons$id ]['bfdate'] ) && empty( $this->arr_persons$id ]['dfdate'] ) ) //no dates, delete this guy
      
{
        unset( 
$this->arr_persons$id ] );
      }
    }
  }

  
public function get_persons()
  {
    return 
$this->arr_persons;
  }
  
  
protected function clean_date(&$str)
  {
    
preg_match'/(\d{2}\.\d{2}\.\d{4})/'$str$match);
    
$str = ( empty($match) ? '' $match[1] );
  }
    
}

 
  Advertise on this site Advertise on this site   Site map Site map   Statistics Statistics   Site tips Site tips   Privacy policy Privacy policy   Contact Contact  

For more information send a message to :
info at phpclasses dot org.
Copyright (c) Icontem 1999-2009 PHP Classes - PHP Class Scripts
  PHP Book Reviews - Reviews of books and other products