<?php
/**
 * Utility class to access OpenDocument spreadsheets read-only
 *
 * Requires PHP 5.0.3
 *
 * @version $Id: Calc_Reader.php,v 1.1 2005-02-27 10:58:44 marand Exp $
 * @license CeCILL 2.0
 * @copyright 2005 Ouest Systemes Informatiques
 */

$erCalc_Reader = error_reporting(E_ALL | E_STRICT);

/**
 * Utility class to access OpenDocument spreadsheets read-only
 */
class Calc_Reader
  {
  const NS_TABLE  = "urn:oasis:names:tc:opendocument:xmlns:table:1.0";
  const NS_OFFICE = "urn:oasis:names:tc:opendocument:xmlns:office:1.0";
  
  /**
   * @var DOMDocument $xml
   */
  public $xml;
  
  /**
   * @var DOMXPath $xpath
   */
  public $xpath;
  
  function __construct($path)
    {
    $this->xml = new DOMDocument();
    $this->xml->preserveWhiteSpace = FALSE;
    $this->xml->load($path);

    $this->xpath = new DOMXPath($this->xml);
    $this->xpath->registerNameSpace('office', Calc_Reader::NS_OFFICE);
    $this->xpath->registerNameSpace('table', Calc_Reader::NS_TABLE);      
    }

  /**
   * Return the rows in the spreadsheet as a DOMNodeList
   * 
   * @return DOMNodeList
   */
  function getRows ()
    {
    $query = '//table:table-row';
    
    $ret = $this->xpath->query($query);
    unset($query);
    
    return $ret;  
    }
  }
  
error_reporting($erCalc_Reader);
unset ($erCalc_Reader);