Documentation
¶
Overview ¶
Package marcxml reads and writes MARC 21 records in the Library of Congress MARCXML "slim" serialization (namespace http://www.loc.gov/MARC21/slim), implementing codex.RecordReader and codex.RecordWriter using only encoding/xml.
A MARCXML document is a <collection> of <record> elements, each holding a <leader>, <controlfield> elements (tags below "010") and <datafield> elements carrying two indicator attributes and <subfield> children. Values are UTF-8 and are XML-escaped on write. Decoding is namespace-agnostic, so documents with or without the slim namespace (and a bare <record> with no <collection> wrapper) are accepted.
Index ¶
Constants ¶
const Namespace = "http://www.loc.gov/MARC21/slim"
Namespace is the MARCXML slim schema namespace.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode parses a single record from a MARCXML byte slice (a <record>, or the first record of a <collection>).
func Encode ¶
Encode serializes a record as a standalone MARCXML <record> element, indented and carrying the slim namespace declaration. Use a Writer to emit a full <collection> document.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads MARC records from a MARCXML stream one <record> at a time. It does not buffer the whole document.
func (*Reader) All ¶
All returns an iterator over the remaining records in the stream, for use as "for rec, err := range r.All()". It stops at the first error.
func (*Reader) Read ¶
Read returns the next record, or io.EOF when the stream is exhausted. It advances to the next <record> element (inside a <collection> or at the top level) and decodes it by walking tokens, so field order is preserved exactly and the reflection cost of struct unmarshaling is avoided.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer streams records into a MARCXML <collection>. Close must be called to emit the closing </collection> and complete the document.