cvs: peardoc /en/package/fileformats file-marc.xml /en/package/fileformats/file-marc formatting.xml reading.xml

From: Date: Fri, 23 Feb 2007 01:15:47 +0000
Subject: cvs: peardoc /en/package/fileformats file-marc.xml /en/package/fileformats/file-marc formatting.xml reading.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-9459@lists.php.net to get a copy of this message
dbs Fri Feb 23 01:15:47 2007 UTC Added files: /peardoc/en/package/fileformats/file-marc formatting.xml Modified files: /peardoc/en/package/fileformats file-marc.xml /peardoc/en/package/fileformats/file-marc reading.xml Log: Add documentation about formatting MARC data. Correct some references to File_MARC_DataField (should be File_MARC_Data_Field).

http://cvs.php.net/viewvc.cgi/peardoc/en/package/fileformats/file-marc.xml?r1=1.2&r2=1.3&diff_format=u Index: peardoc/en/package/fileformats/file-marc.xml diff -u peardoc/en/package/fileformats/file-marc.xml:1.2 peardoc/en/package/fileformats/file-marc.xml:1.3 --- peardoc/en/package/fileformats/file-marc.xml:1.2 Mon Feb 12 22:10:53 2007 +++ peardoc/en/package/fileformats/file-marc.xml Fri Feb 23 01:15:47 2007 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <sect1 id="package.fileformats.file-marc"> <title>File_MARC</title> @@ -9,10 +9,10 @@ <!-- &package.fileformats.file-marc.intro; - &package.fileformats.file-marc.creating; &package.fileformats.file-marc.modifying; --> &package.fileformats.file-marc.reading; + &package.fileformats.file-marc.formatting; </sect1> <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/viewvc.cgi/peardoc/en/package/fileformats/file-marc/reading.xml?r1=1.2&r2=1.3&diff_format=u Index: peardoc/en/package/fileformats/file-marc/reading.xml diff -u peardoc/en/package/fileformats/file-marc/reading.xml:1.2 peardoc/en/package/fileformats/file-marc/reading.xml:1.3 --- peardoc/en/package/fileformats/file-marc/reading.xml:1.2 Tue Feb 20 01:49:53 2007 +++ peardoc/en/package/fileformats/file-marc/reading.xml Fri Feb 23 01:15:47 2007 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> <refentry id="package.fileformats.file-marc.reading"> <refnamediv> <refname>Reading MARC data</refname> @@ -91,9 +91,9 @@ A <classname>File_MARC</classname> object consists of a leader and an iterable set of <classname>File_MARC_Record</classname> objects representing MARC records. Each of these, in turn, consists of an - iterable set of <classname>File_MARC_DataField</classname> or - <classname>File_MARC_ControlField</classname> objects representing MARC - fields. A <classname>File_MARC_DataField</classname> consists of a set of + iterable set of <classname>File_MARC_Data_Field</classname> or + <classname>File_MARC_Control_Field</classname> objects representing MARC + fields. A <classname>File_MARC_Data_Field</classname> consists of a set of iterable <classname>File_MARC_Subfield</classname> objects representing MARC subfields. </para> @@ -180,7 +180,7 @@ <refsect1 id="package.fileformats.file-marc.reading.iterating"> <title>Iterating through fields and subfields</title> <para> - When you iterate over a <classname>File_MARC_DataField</classname> object + When you iterate over a <classname>File_MARC_Data_Field</classname> object using <function>foreach</function>, the MARC tag for the given field is returned as the key for the element and the set of subfields is returned as the value of the element. @@ -226,6 +226,42 @@ </refsect1> + <refsect1 id="package.fileformats.file-marc.reading.indicators"> + <title>Retrieving field indicators</title> + <para> + Data fields, represented by the <classname>File_MARC_Data_Field</classname> + class, offer a <function>getIndicator</function> function to enable you to + retrieve the value of an indicator. + </para> + + <example> + <title>Retrieving an indicator</title> + <para> + In the following example, we retrieve the title (245) field of a MARC + record and check the second indicator for the field to determine whether + there are non-filing indicators that we should ignore when sorting the + contents of the field. + </para> + <programlisting role="php"><![CDATA[ +require 'File/MARC.php'; + +$titleField = $record->getField('245'); +$nonfiling = $titleField->getIndicator(2); + +if ($nonfiling) { + // Sort using the subset of the $a subfield + $title = substr($titleField->getSubfield('a), $nonfiling); +} else { + // Sort using the entire contents of the $a subfield + $title = $titleField->getSubfield('a'); +} +]]> + </programlisting> + + </example> + + </refsect1> + </refentry> <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/viewvc.cgi/peardoc/en/package/fileformats/file-marc/formatting.xml?view=markup&rev=1.1 Index: peardoc/en/package/fileformats/file-marc/formatting.xml +++ peardoc/en/package/fileformats/file-marc/formatting.xml <!-- $Revision: 1.1 $ --> <refentry id="package.fileformats.file-marc.formatting"> <refnamediv> <refname>Formatting MARC data</refname> <refpurpose> Formatting MARC data with <classname>File_MARC</classname> </refpurpose> </refnamediv> <refsect1 id="package.fileformats.file-marc.formatting.overview"> <title>Overview</title> <para> The <classname>File_MARC_Record</classname> class enables you to write Machine Readable Cataloging (<acronym>MARC</acronym>) data in MARC 21 format, in a human-readable string format, and (with some restrictions) in MARCXML format. </para> </refsect1> <refsect1 id="package.fileformats.file-marc.formatting.marc21"> <title>Formatting MARC 21 data</title> <para> To return a record in MARC 21 format, call the <function>toRaw()</function> method on the <classname>File_MARC_Record</classname> object. </para> <example> <title>Writing MARC 21 data to a file</title> <para> In the following example, we have created one or more MARC records represented by <classname>File_MARC_Record</classname> objects stored in the <varname>$records</varname> array. To write this data to a file in MARC 21 format, we simply open the file in binary mode and write the contents of the records in the array to the file by calling the <function>toRaw()</function> method on each record in turn. </para> <programlisting role="php"><![CDATA[ require 'File/MARC.php'; // convert_metadata_to_marc() is a fictional method // that returns an array of File_MARC_Record objects $records = convert_metadata_to_marc(); // Open a file for binary write access $marc21_file = fopen("records.mrc", "wb"); // Iterate through the records while ($record = $records->next()) { // Write each record to the file in MARC 21 format fwrite($marc21_file, $record->toRaw()); } // Close the file fclose($marc21_file); ]]> </programlisting> </example> </refsect1> <refsect1 id="package.fileformats.file-marc.formatting.human"> <title>Creating human-readable output from MARC data</title> <para> To return a human-readable version of a MARC 21 or MARCXML record, call the <function>__toString()</function> method on the <classname>File_MARC_Record</classname> object. Note that you call the <function>__toString()</function> method implicitly when you call the <function>print()</function> function on a <classname>File_MARC_Record</classname> object. </para> <example> <title>Returning a human-readable representation of MARC</title> <para> In the following example, we print the contents of each MARC record in a human-readable format and also explicitly call the <function>__toString()</function> method so that we can write the human-readable contents to a file. Notice that it does not matter whether the source format is MARC or MARCXML, the methods we call to format the data for output are the same. </para> <programlisting role="php"><![CDATA[ require 'File/MARCXML.php'; // Retrieve a set of MARCXML records from a string $journals = new File_MARCXML($xml_data, SOURCE_STRING); // Open a file for binary write access $marc21_file = fopen("records.mrc", "wb"); // Iterate through the retrieved records while ($record = $journals->next()) { // Pretty print each record print $record; print "\n"; // Write the pretty-printed record to file fwrite($marc21_file, $record->__toString() . "\n"); } // Close the file fclose($marc21_file); ]]> </programlisting> </example> </refsect1> <refsect1 id="package.fileformats.file-marc.writing.marcxml"> <title>Formatting MARCXML data</title> <para> To return a record in MARCXML format, call the <function>toXML()</function> method on the <classname>File_MARC_Record</classname> object. </para> <warning> <title>Significant restrictions on the <function>toXML()</function> method</title> <itemizedlist> <listitem> <para> Most significantly, PHP offers no means of converting from the MARC8 encoding that most legacy MARC records have been encoded in to a valid XML encoding such as UTF-8. MARC libraries in other languages have worked around this basic lack of infrastructure by creating their own character encoding conversion libraries. At this time, the author of <classname>File_MARC</classname> does not have the capacity to build the same support as a PEAR package but would welcome any assistance. Better still would be the addition of ANSEL and MARC8 encoding support to the iconv and ICU toolkits that are used to supply encoding conversion by most open-source projects and languages. </para> </listitem> <listitem> <para> The <function>toXML()</function> method currently produces a single, complete, valid XML MARCXML document for a single <classname>File_MARC_Record</classname> object. You cannot simply concatenate the results of calling <function>toXML()</function> on two <classname>File_MARC_Record</classname> objects, because that will produce invalid an invalid XML document. At this time, it is up to the developer to extract the <varname>record</varname> node from each MARCXML document and concatenate them inside a <varname>collection</varname> root element if they want to create a MARCXML document that contains more than a single record. </para> </listitem> </itemizedlist> </warning> <example> <title>Writing MARCXML data to a file</title> <para> In the following example, we have created a MARC record represented by a <classname>File_MARC_Record</classname> object stored in the <varname>$record</varname> variable. To write this data to a file in MARCXML format, we simply open the file in binary mode and write the record to the file by calling the <function>toXML()</function> method on the record object. </para> <programlisting role="php"><![CDATA[ require 'File/MARC.php'; // Create a MARC record $record = create_a_marc_record(); // Open a file for binary write access $marcxml_file = fopen("records.mrc", "wb"); // Write the record to the file in MARCXML format fwrite($marcxml_file, $record->toXML()); // Close the file fclose($marcxml_file); ]]> </programlisting> </example> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->
« previous php.pear.doc (#9459) next »