* // Example: Insert a new field before the first 650 field * * // Create the new field * $subfields[] = new File_MARC_Subfield('a', 'Scott, Daniel.'); * $new_field = new File_MARC_Data_Field('100', $subfields, 0, null); * * // Retrieve the target field for our insertion point * $subject = $record->getFields('650'); * * // Insert the new field * if (is_array($subject)) { * $record->insertField($new_field, $subject[0], true); * } * elseif ($subject) { * $record->insertField($new_field, $subject, true); * } *
* // Example: Modify a record and save the output to a file * $record->deleteFields('650'); * * // Now that the record has no subject fields, save it to disk * fopen($file, '/home/dan/no_subject.mrc', 'w'); * fwrite($file, $record->toRaw()); * fclose($file); *
* _ * * @return string Formatted representation of MARC record */ function __toString() { // Begin output $formatted = "LDR " . $this->leader . "\n"; foreach ($this->fields as $field) { if (!$field->isEmpty()) { $formatted .= $field->__toString() . "\n"; } } return $formatted; } // }}} // {{{ toXML() /** * Return the MARC record in MARCXML format * * This method produces an XML representation of a MARC record that * attempts to adhere to the MARCXML standard documented at * http://www.loc.gov/standards/marcxml/ * * @param string $encoding output encoding for the MARCXML record * @param bool $indent pretty-print the MARCXML record * @param bool $single wrap the element in a element * * @return string representation of MARC record in MARCXML format * * @todo Fix encoding input / output issues (PHP 6.0 required?) */ function toXML($encoding = "UTF-8", $indent = true, $single = true) { $this->marcxml->setIndent($indent); if ($single) { $this->marc->toXMLHeader(); } $this->marcxml->startElement("record"); // MARCXML schema has some strict requirements // We'll set reasonable defaults to avoid invalid MARCXML $xmlLeader = $this->getLeader(); // Record status if ($xmlLeader[5] == " ") { // Default to "n" (new record) $xmlLeader[5] = "n"; } // Type of record if ($xmlLeader[6] == " ") { // Default to "a" (language material) $xmlLeader[6] = "a"; } $this->marcxml->writeElement("leader", $xmlLeader); foreach ($this->fields as $field) { if (!$field->isEmpty()) { switch(get_class($field)) { case "File_MARC_Control_Field": $this->marcxml->startElement("controlfield"); $this->marcxml->writeAttribute("tag", $field->getTag()); $this->marcxml->text($field->getData()); $this->marcxml->endElement(); // end control field break; case "File_MARC_Data_Field": $this->marcxml->startElement("datafield"); $this->marcxml->writeAttribute("tag", $field->getTag()); $this->marcxml->writeAttribute("ind1", $field->getIndicator(1)); $this->marcxml->writeAttribute("ind2", $field->getIndicator(2)); foreach ($field->getSubfields() as $subfield) { $this->marcxml->startElement("subfield"); $this->marcxml->writeAttribute("code", $subfield->getCode()); $this->marcxml->text($subfield->getData()); $this->marcxml->endElement(); // end subfield } $this->marcxml->endElement(); // end data field break; } } } $this->marcxml->endElement(); // end record if ($single) { return $this->marc->toXMLFooter(); } } // }}} } // }}}
* * @return string Formatted representation of MARC record */ function __toString() { // Begin output $formatted = "LDR " . $this->leader . "\n"; foreach ($this->fields as $field) { if (!$field->isEmpty()) { $formatted .= $field->__toString() . "\n"; } } return $formatted; } // }}} // {{{ toXML() /** * Return the MARC record in MARCXML format * * This method produces an XML representation of a MARC record that * attempts to adhere to the MARCXML standard documented at * http://www.loc.gov/standards/marcxml/ * * @param string $encoding output encoding for the MARCXML record * @param bool $indent pretty-print the MARCXML record * @param bool $single wrap the element in a element * * @return string representation of MARC record in MARCXML format * * @todo Fix encoding input / output issues (PHP 6.0 required?) */ function toXML($encoding = "UTF-8", $indent = true, $single = true) { $this->marcxml->setIndent($indent); if ($single) { $this->marc->toXMLHeader(); } $this->marcxml->startElement("record"); // MARCXML schema has some strict requirements // We'll set reasonable defaults to avoid invalid MARCXML $xmlLeader = $this->getLeader(); // Record status if ($xmlLeader[5] == " ") { // Default to "n" (new record) $xmlLeader[5] = "n"; } // Type of record if ($xmlLeader[6] == " ") { // Default to "a" (language material) $xmlLeader[6] = "a"; } $this->marcxml->writeElement("leader", $xmlLeader); foreach ($this->fields as $field) { if (!$field->isEmpty()) { switch(get_class($field)) { case "File_MARC_Control_Field": $this->marcxml->startElement("controlfield"); $this->marcxml->writeAttribute("tag", $field->getTag()); $this->marcxml->text($field->getData()); $this->marcxml->endElement(); // end control field break; case "File_MARC_Data_Field": $this->marcxml->startElement("datafield"); $this->marcxml->writeAttribute("tag", $field->getTag()); $this->marcxml->writeAttribute("ind1", $field->getIndicator(1)); $this->marcxml->writeAttribute("ind2", $field->getIndicator(2)); foreach ($field->getSubfields() as $subfield) { $this->marcxml->startElement("subfield"); $this->marcxml->writeAttribute("code", $subfield->getCode()); $this->marcxml->text($subfield->getData()); $this->marcxml->endElement(); // end subfield } $this->marcxml->endElement(); // end data field break; } } } $this->marcxml->endElement(); // end record if ($single) { return $this->marc->toXMLFooter(); } } // }}} } // }}}