/** * Read in MARC records * * This function reads in MARC record files or strings that * contain one or more MARC records. * * <code> * <?php * // Retrieve MARC records from a file * $journals = new File_MARC('journals.mrc', SOURCE_FILE); * * // Retrieve MARC records from a string (e.g. Z39 query results) * $monographs = new File_MARC($raw_marc, SOURCE_STRING); * ?> * </code> * * @param string $source Name of the file, or a raw MARC string * @param int $type Source of the input, either SOURCE_FILE or SOURCE_STRING */ function __construct($source, $type = self::SOURCE_FILE) { parent::__construct($source, $type); switch ($type) { case self::SOURCE_FILE: $this->type = self::SOURCE_FILE; $this->source = fopen($source, 'rb'); if (!$this->source) { $errorMessage = File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_FILE], array('filename' => $source)); throw new File_MARC_Exception($errorMessage, File_MARC_Exception::ERROR_INVALID_FILE); } break; case self::SOURCE_STRING: $this->type = self::SOURCE_STRING; $this->source = explode(File_MARC::END_OF_RECORD, $source); break; default: throw new File_MARC_Exception(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_SOURCE], File_MARC_Exception::ERROR_INVALID_SOURCE); } }
/** * Read in MARCXML records * * This function reads in files or strings that * contain one or more MARCXML records. * * <code> * <?php * // Retrieve MARC records from a file * $journals = new File_MARC('journals.mrc', SOURCE_FILE); * * // Retrieve MARC records from a string (e.g. Z39 query results) * $monographs = new File_MARC($raw_marc, SOURCE_STRING); * * // Retrieve MARCXML records from a string with a namespace URL * $records = new File_MARCXML($xml_data, File_MARC::SOURCE_STRING,"http://www.loc.gov/MARC21/slim"); * * // Retrieve MARCXML records from a file with a namespace prefix * $records = new File_MARCXML($xml_data, File_MARC::SOURCE_FILE,"marc",true); * ?> * </code> * * @param string $source Name of the file, or a raw MARC string * @param int $type Source of the input, either SOURCE_FILE or SOURCE_STRING * @param string $ns URI or prefix of the namespace * @param bool $is_prefix TRUE if $ns is a prefix, FALSE if it's a URI; defaults to FALSE */ function __construct($source, $type = self::SOURCE_FILE, $ns = "", $is_prefix = false) { parent::__construct($source, $type); $this->counter = 0; switch ($type) { case self::SOURCE_FILE: $this->type = self::SOURCE_FILE; $this->source = simplexml_load_file($source, "SimpleXMLElement", 0, $ns, $is_prefix); break; case self::SOURCE_STRING: $this->type = self::SOURCE_STRING; $this->source = simplexml_load_string($source, "SimpleXMLElement", 0, $ns, $is_prefix); break; default: throw new File_MARC_Exception(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_SOURCE], File_MARC_Exception::ERROR_INVALID_SOURCE); } if (!$this->source) { $errorMessage = File_MARC_Exception::formatError(File_MARC_Exception::$messages[File_MARC_Exception::ERROR_INVALID_FILE], array('filename' => $source)); throw new File_MARC_Exception($errorMessage, File_MARC_Exception::ERROR_INVALID_FILE); } }