cvs: pear /File_MARC .cvsignore CHANGELOG MARCXML.php package.xml /File_MARC/tests marc_xml_001.phpt marc_xml_002.phpt marc_xml_003.phpt sandburg.mrc
sandburg.xml

From: Date: Tue, 02 Jan 2007 02:12:33 +0000
Subject: cvs: pear /File_MARC .cvsignore CHANGELOG MARCXML.php package.xml /File_MARC/tests marc_xml_001.phpt marc_xml_002.phpt marc_xml_003.phpt sandburg.mrc
sandburg.xml
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-43918@lists.php.net to get a copy of this message
dbs Tue Jan 2 02:12:33 2007 UTC Added files: /pear/File_MARC MARCXML.php .cvsignore /pear/File_MARC/tests sandburg.mrc sandburg.xml marc_xml_002.phpt marc_xml_003.phpt Modified files: /pear/File_MARC package.xml CHANGELOG /pear/File_MARC/tests marc_xml_001.phpt Log: Add File_MARCXML support for reading MARCXML source + tests

http://cvs.php.net/viewvc.cgi/pear/File_MARC/package.xml?r1=1.2&r2=1.3&diff_format=u Index: pear/File_MARC/package.xml diff -u pear/File_MARC/package.xml:1.2 pear/File_MARC/package.xml:1.3 --- pear/File_MARC/package.xml:1.2 Mon Jan 1 21:40:33 2007 +++ pear/File_MARC/package.xml Tue Jan 2 02:12:32 2007 @@ -37,12 +37,15 @@ <license uri="http://www.gnu.org/copyleft/lesser.html">GNU Lesser General Public License</license> <notes> 0.1.1-alpha -* Add rudimentary toXML() method for records +* Add rudimentary File_MARC_Record->toXML() method for converting MARC21 + records to MARCXML format +* Add File_MARCXML class for reading MARCXML records </notes> <contents> <dir name="/" baseinstalldir="File"> <file name="CHANGELOG" role="doc" /> <file name="MARC.php" role="php" /> + <file name="MARCXML.php" role="php" /> <file name="LICENSE" role="doc" /> <dir name="MARC"> <file name="Control_Field.php" role="php" /> @@ -68,13 +71,20 @@ <file name="marc_005.phpt" role="test" /> <file name="marc_006.phpt" role="test" /> <file name="marc_007.phpt" role="test" /> + <file name="marc_008.phpt" role="test" /> + <file name="marc_010.phpt" role="test" /> <file name="marc_field_001.phpt" role="test" /> <file name="marc_field_002.phpt" role="test" /> <file name="marc_field_003.phpt" role="test" /> <file name="marc_field_004.phpt" role="test" /> <file name="marc_subfield_001.phpt" role="test" /> <file name="marc_subfield_002.phpt" role="test" /> + <file name="marc_xml_001.phpt" role="test" /> + <file name="marc_xml_002.phpt" role="test" /> + <file name="marc_xml_003.phpt" role="test" /> <file name="music.mrc" role="test" /> + <file name="sandburg.mrc" role="test" /> + <file name="sandburg.xml" role="test" /> </dir> </dir> </contents> http://cvs.php.net/viewvc.cgi/pear/File_MARC/CHANGELOG?r1=1.1&r2=1.2&diff_format=u Index: pear/File_MARC/CHANGELOG diff -u pear/File_MARC/CHANGELOG:1.1 pear/File_MARC/CHANGELOG:1.2 --- pear/File_MARC/CHANGELOG:1.1 Tue Nov 14 18:12:57 2006 +++ pear/File_MARC/CHANGELOG Tue Jan 2 02:12:32 2007 @@ -1,3 +1,12 @@ +0.1.1-alpha +* Add File_MARC_Record::toXML() method for generating MARCXML output +* Add File_MARCXML class for reading MARCXML source +* Add tests for MARCXML methods + +0.1.0-alpha +* Split each class out into its own file +* Do not return anything from constructors + 0.0.9-alpha * Separate getFields() from getField(), getSubfields() from getSubfield() to avoid forcing users to test is_array() after every call http://cvs.php.net/viewvc.cgi/pear/File_MARC/tests/marc_xml_001.phpt?r1=1.1&r2=1.2&diff_format=u Index: pear/File_MARC/tests/marc_xml_001.phpt diff -u pear/File_MARC/tests/marc_xml_001.phpt:1.1 pear/File_MARC/tests/marc_xml_001.phpt:1.2 --- pear/File_MARC/tests/marc_xml_001.phpt:1.1 Mon Jan 1 21:40:33 2007 +++ pear/File_MARC/tests/marc_xml_001.phpt Tue Jan 2 02:12:33 2007 @@ -1,5 +1,5 @@ --TEST-- -marc_001: iterate and pretty print a MARC record +marc_xml_001: iterate and pretty print a MARC record --FILE-- <?php $dir = dirname(__FILE__); http://cvs.php.net/viewvc.cgi/pear/File_MARC/MARCXML.php?view=markup&rev=1.1 Index: pear/File_MARC/MARCXML.php +++ pear/File_MARC/MARCXML.php <?php /* vim: set expandtab shiftwidth=4 tabstop=4 softtabstop=4 foldmethod=marker: */ /** * Parser for MARC records * * This package is based on the PHP MARC package, originally called "php-marc", * that is part of the Emilda Project (http://www.emilda.org). Christoffer * Landtman generously agreed to make the "php-marc" code available under the * GNU LGPL so it could be used as the basis of this PEAR package. * * PHP version 5 * * LICENSE: This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * * @category File Formats * @package File_MARC * @author Dan Scott <dscott@laurentian.ca> * @copyright 2007 Dan Scott * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @version CVS: $Id: MARCXML.php,v 1.1 2007/01/02 02:12:32 dbs Exp $ * @link http://pear.php.net/package/File_MARC * @example read.php Retrieve specific fields and subfields from a record * @example subfields.php Create new subfields and add them in specific order * @example marc_yaz.php Pretty print a MARC record retrieved through the PECL yaz extension */ require_once 'PEAR/Exception.php'; require_once 'Structures/LinkedList/Double.php'; require_once 'File/MARC.php'; require_once 'File/MARC/Record.php'; require_once 'File/MARC/Field.php'; require_once 'File/MARC/Control_Field.php'; require_once 'File/MARC/Data_Field.php'; require_once 'File/MARC/Subfield.php'; require_once 'File/MARC/Exception.php'; require_once 'File/MARC/List.php'; // {{{ class File_MARCXML /** * The main File_MARCXML class enables you to return File_MARC_Record * objects from an XML stream or string. * * @category File Formats * @package File_MARC * @author Dan Scott <dscott@laurentian.ca> * @license http://www.gnu.org/copyleft/lesser.html LGPL License 2.1 * @link http://pear.php.net/package/File_MARC */ class File_MARCXML { // {{{ constants /** * MARC records retrieved from a file */ const SOURCE_FILE = 1; /** * MARC records retrieved from a binary string */ const SOURCE_STRING = 2; // }}} // {{{ properties /** * Source containing raw records * * @var resource */ protected $source; /** * Source type (SOURCE_FILE or SOURCE_STRING) * * @var int */ protected $type; /** * Counter for MARCXML records in a collection * * @var int */ protected $counter; // }}} // {{{ Constructor: function __construct() /** * 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); * ?> * </code> * * @param string $in Name of the file, or a raw MARC string * @param int $source Source of the input, either SOURCE_FILE * or SOURCE_STRING */ function __construct($source, $type = self::SOURCE_FILE) { $this->counter = 0; switch ($type) { case self::SOURCE_FILE: $this->type = self::SOURCE_FILE; $this->source = simplexml_load_file($source); break; case self::SOURCE_STRING: $this->type = self::SOURCE_STRING; $this->source = simplexml_load_string($source); 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); } } // }}} // {{{ next() /** * Return next {@link File_MARC_Record} object * * Decodes the next MARCXML record and returns the {@link File_MARC_Record} * object. * <code> * <?php * // Retrieve a set of MARCXML records from a file * $journals = new File_MARCXML('journals.xml', SOURCE_FILE); * * // Iterate through the retrieved records * while ($record = $journals->next()) { * print $record; * print "\n"; * } * * ?> * </code> * * @return File_MARC_Record next record, or false if there are * no more records */ function next() { if ($record = $this->source->record[$this->counter++]) { return $this->_decode($record); } else { return false; } } // }}} // {{{ _decode() /** * Decode a given MARCXML record * * @param string $text MARCXML record element * @return File_MARC_Record Decoded File_MARC_Record object */ private function _decode($text) { $marc = new File_MARC_Record(); // Store leader $marc->setLeader($text->leader); // go through all the control fields foreach ($text->controlfield as $controlfield) { $marc->appendField(new File_MARC_Control_Field($controlfield['tag'], $controlfield)); } // go through all the data fields foreach ($text->datafield as $datafield) { $subfield_data = array(); foreach($datafield->subfield as $subfield) { $subfield_data[] = new File_MARC_Subfield($subfield['code'], $subfield); } $marc->appendField(new File_MARC_Data_Field($datafield['tag'], $subfield_data, $datafield['ind1'], $datafield['ind2'])); } return $marc; } // }}} } // }}} http://cvs.php.net/viewvc.cgi/pear/File_MARC/.cvsignore?view=markup&rev=1.1 Index: pear/File_MARC/.cvsignore +++ pear/File_MARC/.cvsignore *~ http://cvs.php.net/viewvc.cgi/pear/File_MARC/tests/sandburg.mrc?view=markup&rev=1.1 Index: pear/File_MARC/tests/sandburg.mrc +++ pear/File_MARC/tests/sandburg.mrc 01142cam 2200301 a 4500001001300000003000400013005001700017008004100034010001700075020002500092040001800117042000900135050002600144082001600170100003200186245008600218250001200304260005200316300004900368500004000417520022800457650003300685650003300718650002400751650002100775650002300796700002100819 92005291 DLC19930521155141.9920219s1993 caua j 000 0 eng  a 92005291  a0152038655 :c$15.95 aDLCcDLCdDLC alcac00aPS3537.A618bA88 199300a811/.522201 aSandburg, Carl,d1878-1967.10aArithmetic /cCarl Sandburg ; illustrated as an anamorphic adventure by Ted Rand. a1st ed. aSan Diego :bHarcourt Brace Jovanovich,cc1993. a1 v. (unpaged) :bill. (some col.) ;c26 cm. aOne Mylar sheet included in pocket. aA poem about numbers and their characteristics. Features anamorphic, or distorted, drawings which can be restored to normal by viewing from a particular angle or by viewing the image's reflection in the provided Mylar cone. 0! aArithmeticxJuvenile poetry. 0aChildren's poetry, American. 1aArithmeticxPoetry. 1aAmerican poetry. 1aVisual perception.1 aRand, Ted,eill. http://cvs.php.net/viewvc.cgi/pear/File_MARC/tests/sandburg.xml?view=markup&rev=1.1 Index: pear/File_MARC/tests/sandburg.xml +++ pear/File_MARC/tests/sandburg.xml <?xml version="1.0" encoding="UTF-8"?> <collection xmlns="http://www.loc.gov/MARC21/slim"> <record> <leader>01142cam 2200301 a 4500</leader> <controlfield tag="001"> 92005291 </controlfield> <controlfield tag="003">DLC</controlfield> <controlfield tag="005">19930521155141.9</controlfield> <controlfield tag="008">920219s1993 caua j 000 0 eng </controlfield> <datafield tag="010" ind1=" " ind2=" "> <subfield code="a"> 92005291 </subfield> </datafield> <datafield tag="020" ind1=" " ind2=" "> <subfield code="a">0152038655 :</subfield> <subfield code="c">$15.95</subfield> </datafield> <datafield tag="040" ind1=" " ind2=" "> <subfield code="a">DLC</subfield> <subfield code="c">DLC</subfield> <subfield code="d">DLC</subfield> </datafield> <datafield tag="042" ind1=" " ind2=" "> <subfield code="a">lcac</subfield> </datafield> <datafield tag="050" ind1="0" ind2="0"> <subfield code="a">PS3537.A618</subfield> <subfield code="b">A88 1993</subfield> </datafield> <datafield tag="082" ind1="0" ind2="0"> <subfield code="a">811/.52</subfield> <subfield code="2">20</subfield> </datafield> <datafield tag="100" ind1="1" ind2=" "> <subfield code="a">Sandburg, Carl,</subfield> <subfield code="d">1878-1967.</subfield> </datafield> <datafield tag="245" ind1="1" ind2="0"> <subfield code="a">Arithmetic /</subfield> <subfield code="c">Carl Sandburg ; illustrated as an anamorphic adventure by Ted Rand.</subfield> </datafield> <datafield tag="250" ind1=" " ind2=" "> <subfield code="a">1st ed.</subfield> </datafield> <datafield tag="260" ind1=" " ind2=" "> <subfield code="a">San Diego :</subfield> <subfield code="b">Harcourt Brace Jovanovich,</subfield> <subfield code="c">c1993.</subfield> </datafield> <datafield tag="300" ind1=" " ind2=" "> <subfield code="a">1 v. (unpaged) :</subfield> <subfield code="b">ill. (some col.) ;</subfield> <subfield code="c">26 cm.</subfield> </datafield> <datafield tag="500" ind1=" " ind2=" "> <subfield code="a">One Mylar sheet included in pocket.</subfield> </datafield> <datafield tag="520" ind1=" " ind2=" "> <subfield code="a">A poem about numbers and their characteristics. Features anamorphic, or distorted, drawings which can be restored to normal by viewing from a particular angle or by viewing the image's reflection in the provided Mylar cone.</subfield> </datafield> <datafield tag="650" ind1=" " ind2="0"> <subfield code="a">Arithmetic</subfield> <subfield code="x">Juvenile poetry.</subfield> </datafield> <datafield tag="650" ind1=" " ind2="0"> <subfield code="a">Children's poetry, American.</subfield> </datafield> <datafield tag="650" ind1=" " ind2="1"> <subfield code="a">Arithmetic</subfield> <subfield code="x">Poetry.</subfield> </datafield> <datafield tag="650" ind1=" " ind2="1"> <subfield code="a">American poetry.</subfield> </datafield> <datafield tag="650" ind1=" " ind2="1"> <subfield code="a">Visual perception.</subfield> </datafield> <datafield tag="700" ind1="1" ind2=" "> <subfield code="a">Rand, Ted,</subfield> <subfield code="e">ill.</subfield> </datafield> </record> </collection> http://cvs.php.net/viewvc.cgi/pear/File_MARC/tests/marc_xml_002.phpt?view=markup&rev=1.1 Index: pear/File_MARC/tests/marc_xml_002.phpt +++ pear/File_MARC/tests/marc_xml_002.phpt --TEST-- marc_xml_002: iterate and pretty print a MARC record (LOC standard) --FILE-- <?php $dir = dirname(__FILE__); require $dir . '/../' . 'MARC.php'; $marc_file = new File_MARC($dir . '/' . 'sandburg.mrc'); while ($marc_record = $marc_file->next()) { print $marc_record->toXML(); print "\n"; } ?> --EXPECT-- <?xml version="1.0" encoding="UTF-8"?> <collection xmlns="http://www.loc.gov/MARC21/slim"> <record> <leader>01142cam 2200301 a 4500</leader> <controlfield tag="001"> 92005291 </controlfield> <controlfield tag="003">DLC</controlfield> <controlfield tag="005">19930521155141.9</controlfield> <controlfield tag="008">920219s1993 caua j 000 0 eng </controlfield> <datafield tag="010" ind1=" " ind2=" "> <subfield code="a"> 92005291 </subfield> </datafield> <datafield tag="020" ind1=" " ind2=" "> <subfield code="a">0152038655 :</subfield> <subfield code="c">$15.95</subfield> </datafield> <datafield tag="040" ind1=" " ind2=" "> <subfield code="a">DLC</subfield> <subfield code="c">DLC</subfield> <subfield code="d">DLC</subfield> </datafield> <datafield tag="042" ind1=" " ind2=" "> <subfield code="a">lcac</subfield> </datafield> <datafield tag="050" ind1="0" ind2="0"> <subfield code="a">PS3537.A618</subfield> <subfield code="b">A88 1993</subfield> </datafield> <datafield tag="082" ind1="0" ind2="0"> <subfield code="a">811/.52</subfield> <subfield code="2">20</subfield> </datafield> <datafield tag="100" ind1="1" ind2=" "> <subfield code="a">Sandburg, Carl,</subfield> <subfield code="d">1878-1967.</subfield> </datafield> <datafield tag="245" ind1="1" ind2="0"> <subfield code="a">Arithmetic /</subfield> <subfield code="c">Carl Sandburg ; illustrated as an anamorphic adventure by Ted Rand.</subfield> </datafield> <datafield tag="250" ind1=" " ind2=" "> <subfield code="a">1st ed.</subfield> </datafield> <datafield tag="260" ind1=" " ind2=" "> <subfield code="a">San Diego :</subfield> <subfield code="b">Harcourt Brace Jovanovich,</subfield> <subfield code="c">c1993.</subfield> </datafield> <datafield tag="300" ind1=" " ind2=" "> <subfield code="a">1 v. (unpaged) :</subfield> <subfield code="b">ill. (some col.) ;</subfield> <subfield code="c">26 cm.</subfield> </datafield> <datafield tag="500" ind1=" " ind2=" "> <subfield code="a">One Mylar sheet included in pocket.</subfield> </datafield> <datafield tag="520" ind1=" " ind2=" "> <subfield code="a">A poem about numbers and their characteristics. Features anamorphic, or distorted, drawings which can be restored to normal by viewing from a particular angle or by viewing the image's reflection in the provided Mylar cone.</subfield> </datafield> <datafield tag="650" ind1=" " ind2="0"> <subfield code="a">Arithmetic</subfield> <subfield code="x">Juvenile poetry.</subfield> </datafield> <datafield tag="650" ind1=" " ind2="0"> <subfield code="a">Children's poetry, American.</subfield> </datafield> <datafield tag="650" ind1=" " ind2="1"> <subfield code="a">Arithmetic</subfield> <subfield code="x">Poetry.</subfield> </datafield> <datafield tag="650" ind1=" " ind2="1"> <subfield code="a">American poetry.</subfield> </datafield> <datafield tag="650" ind1=" " ind2="1"> <subfield code="a">Visual perception.</subfield> </datafield> <datafield tag="700" ind1="1" ind2=" "> <subfield code="a">Rand, Ted,</subfield> <subfield code="e">ill.</subfield> </datafield> </record> </collection> http://cvs.php.net/viewvc.cgi/pear/File_MARC/tests/marc_xml_003.phpt?view=markup&rev=1.1 Index: pear/File_MARC/tests/marc_xml_003.phpt +++ pear/File_MARC/tests/marc_xml_003.phpt --TEST-- marc_xml_003: Round-trip a MARCXML record to MARC21 (LOC standard) --FILE-- <?php $dir = dirname(__FILE__); require $dir . '/../' . 'MARCXML.php'; $marc_file = new File_MARCXML($dir . '/' . 'sandburg.xml'); while ($marc_record = $marc_file->next()) { print $marc_record->toRaw(); } ?> --EXPECT-- 01142cam 2200301 a 4500001001300000003000400013005001700017008004100034010001700075020002500092040001800117042000900135050002600144082001600170100003200186245008600218250001200304260005200316300004900368500004000417520022800457650003300685650003300718650002400751650002100775650002300796700002100819 92005291 DLC19930521155141.9920219s1993 caua j 000 0 eng  a 92005291  a0152038655 :c$15.95 aDLCcDLCdDLC alcac00aPS3537.A618bA88 199300a811/.522201 aSandburg, Carl,d1878-1967.10aArithmetic /cCarl Sandburg ; illustrated as an anamorphic adventure by Ted Rand. a1st ed. aSan Diego :bHarcourt Brace Jovanovich,cc1993. a1 v. (unpaged) :bill. (some col.) ;c26 cm. aOne Mylar sheet included in pocket. aA poem about numbers and their characteristics. Features anamorphic, or distorted, drawings which can be restored to normal by viewing from a particular angle or by viewing the image's reflection in the provided Mylar cone. 0! aArithmeticxJuvenile poetry. 0aChildren's poetry, American. 1aArithmeticxPoetry. 1aAmerican poetry. 1aVisual perception.1 aRand, Ted,eill.
« previous php.pear.cvs (#43918) next »