PHP Classes
elePHPant
Icontem

File: plugins/DrevoXMLParser.class.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Alexander Skakunov  >  Drevo Export  >  plugins/DrevoXMLParser.class.php  >  Download  
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
Author: By
Last change:
Date: 7 years ago
Size: 1,813 bytes
 

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->r 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] );
  }
   
}