marc

package
v0.0.0-...-0d6871a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2022 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package marc implements decoding of MARCXML (MarcXchange (ISO25577) bibliographic MARC records, and convenience methods for extracting values from record fields.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unmarshal

func Unmarshal(b []byte, rec *Record) error

Unmarshal parsers the MARCXML-encoded data and stores the result in the given Record.

Types

type ControlField

type ControlField struct {
	Tag   string `xml:"tag,attr"`  // 3 chars
	Value string `xml:",chardata"` // if Tag == "000"; 40 chars
}

ControlField represents a control field in a MARC record.

type DataField

type DataField struct {
	Tag       string     `xml:"tag,attr"`  // 3 chars
	Ind1      string     `xml:"ind1,attr"` // 1 char
	Ind2      string     `xml:"ind2,attr"` // 1 char
	SubFields []SubField `xml:"subfield"`
}

DataField represents a data field in a MARC record.

func (DataField) ValueAt

func (d DataField) ValueAt(code string) string

ValueAt returns the first value at the first occurrence of the code in the the DataField. It returns an empty string if none is found.

func (DataField) ValuesAt

func (d DataField) ValuesAt(code string) (res []string)

ValuesAt returns a string slice of all occurrences of code in the DataField.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder can decode MARC records from a stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new Decoder for the given reader.

func (*Decoder) Decode

func (d *Decoder) Decode() (Record, error)

Decode decodes and returns a single MARC Record, or and error.

func (*Decoder) DecodeAll

func (d *Decoder) DecodeAll() ([]Record, error)

DecodeAll consumes the input stream and returns all decoded records. If there is an error, it will return, together with the successfully parsed MARC records up til then.

type Record

type Record struct {
	XMLName       xml.Name       `xml:"record"`
	Leader        string         `xml:"leader"` // 24 chars
	ControlFields []ControlField `xml:"controlfield"`
	DataFields    []DataField    `xml:"datafield"`
}

Record represents a MARC record.

func MustParse

func MustParse(b []byte) Record

MustParse parses the give MARCXML-encoded data and records a Record, but panics on errors.

func MustParseString

func MustParseString(s string) Record

MustParseString is like MustParse, except it accepts a string instead.

func (Record) ControlFieldAt

func (r Record) ControlFieldAt(tag string) (ControlField, bool)

ControlFieldAt returns the control field of the given tag, along with a boolean denoting if it was found or not.

func (Record) DataFieldAt

func (r Record) DataFieldAt(tag string) (DataField, bool)

DataFieldAt returns the first occurrence of DataField with the given tag, along with a boolean denoting if it was found or not.

func (Record) DataFieldsAt

func (r Record) DataFieldsAt(tags ...string) (res []DataField)

DataFieldsAt returns all occurrences of DataFields with the given tags.

func (Record) IsEmpty

func (r Record) IsEmpty() bool

IsEmpty returns true if the MARC Record i empty (zero value).

func (Record) ValueAt

func (r Record) ValueAt(tag, code string) string

ValueAt returns the first occurrence of code in the requested DataField. An empty string means no match.

func (Record) ValuesAt

func (r Record) ValuesAt(tag, code string) (res []string)

ValuesAt returns a string slice of all occurrences of code in all occurrences of DataFields of the given tag.

type Relator

type Relator struct {
	// contains filtered or unexported fields
}

Relator is a known Marc relator, associated with a 3-letter code. The codes are maintained by Library of Congress. TODO drop struct; type Relator string suffices

func ParseRelator

func ParseRelator(s string) (Relator, error)

ParseRelator parses the given string and returns a Relator if it matches a known 3-letter Marc Relator code.

func (Relator) Code

func (r Relator) Code() string

Code returns the Marc code for the Realtor.

func (Relator) Label

func (r Relator) Label(tag language.Tag) string

Label returns a string representation of the Marc relator in the desired language. Only Norwegian and English are currently supported.

type SubField

type SubField struct {
	Code  string `xml:"code,attr"` // 1 char
	Value string `xml:",chardata"`
}

SubField represents a sub field in a data field.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL