mods

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package mods converts MARC 21 records to MODS (Metadata Object Description Schema), the Library of Congress XML standard that is richer than MARCXML and near-lossless from MARC.

MODS is a different data model than MARC — titleInfo, name, originInfo, subject, … — so this is a one-way mapping (a crosswalk following the LoC MARC-to-MODS mapping), not a codex.RecordReader. The Writer does implement codex.RecordWriter, so it plugs into codex.Convert as a conversion target:

w := mods.NewWriter(out)
codex.Convert(iso2709.NewReader(src), w)
w.Close()

The crosswalk covers the common fields (title, names, type, origin, physical description, subjects, identifiers, language, notes, record info); fields and subfields outside that set are not carried.

Index

Constants

View Source
const Namespace = "http://www.loc.gov/mods/v3"

Namespace is the MODS version 3 namespace.

Variables

This section is empty.

Functions

func Encode

func Encode(r *codex.Record) ([]byte, error)

Encode converts a record to a standalone MODS document.

func WriteFile

func WriteFile(path string, records []*codex.Record) error

WriteFile converts every record to a MODS collection file.

Types

type Identifier

type Identifier struct {
	Type  string `xml:"type,attr,omitempty"`
	Value string `xml:",chardata"`
}

type Language

type Language struct {
	LanguageTerm LanguageTerm `xml:"languageTerm"`
}

type LanguageTerm

type LanguageTerm struct {
	Type      string `xml:"type,attr,omitempty"`
	Authority string `xml:"authority,attr,omitempty"`
	Value     string `xml:",chardata"`
}

type MODS

type MODS struct {
	XMLName        xml.Name     `xml:"mods"`
	Xmlns          string       `xml:"xmlns,attr,omitempty"`
	Version        string       `xml:"version,attr,omitempty"`
	TitleInfo      []TitleInfo  `xml:"titleInfo"`
	Name           []Name       `xml:"name"`
	TypeOfResource string       `xml:"typeOfResource,omitempty"`
	OriginInfo     *OriginInfo  `xml:"originInfo,omitempty"`
	Language       []Language   `xml:"language"`
	PhysicalDesc   *Physical    `xml:"physicalDescription,omitempty"`
	Note           []Note       `xml:"note"`
	Subject        []Subject    `xml:"subject"`
	Identifier     []Identifier `xml:"identifier"`
	RecordInfo     *RecordInfo  `xml:"recordInfo,omitempty"`
}

MODS is a <mods> record. Empty fields are omitted from the output.

func FromRecord

func FromRecord(r *codex.Record) *MODS

FromRecord maps a MARC record to MODS following the common-field crosswalk. It makes a single pass over the fields, dispatching by tag.

type Name

type Name struct {
	Type     string     `xml:"type,attr,omitempty"`
	NamePart []NamePart `xml:"namePart"`
	Role     *Role      `xml:"role,omitempty"`
}

type NamePart

type NamePart struct {
	Type  string `xml:"type,attr,omitempty"`
	Value string `xml:",chardata"`
}

type Note

type Note struct {
	Type  string `xml:"type,attr,omitempty"`
	Value string `xml:",chardata"`
}

type OriginInfo

type OriginInfo struct {
	Place         []Place `xml:"place"`
	Publisher     string  `xml:"publisher,omitempty"`
	DateIssued    string  `xml:"dateIssued,omitempty"`
	CopyrightDate string  `xml:"copyrightDate,omitempty"`
	Edition       string  `xml:"edition,omitempty"`
}

type Physical

type Physical struct {
	Extent string `xml:"extent,omitempty"`
}

type Place

type Place struct {
	PlaceTerm PlaceTerm `xml:"placeTerm"`
}

type PlaceTerm

type PlaceTerm struct {
	Type  string `xml:"type,attr,omitempty"`
	Value string `xml:",chardata"`
}

type RecordInfo

type RecordInfo struct {
	RecordIdentifier string `xml:"recordIdentifier,omitempty"`
}

type Role

type Role struct {
	RoleTerm RoleTerm `xml:"roleTerm"`
}

type RoleTerm

type RoleTerm struct {
	Type  string `xml:"type,attr,omitempty"`
	Value string `xml:",chardata"`
}

type Subject

type Subject struct {
	Authority  string   `xml:"authority,attr,omitempty"`
	Topic      []string `xml:"topic"`
	Geographic []string `xml:"geographic"`
	Temporal   []string `xml:"temporal"`
	Genre      []string `xml:"genre"`
	Name       *Name    `xml:"name,omitempty"`
}

type TitleInfo

type TitleInfo struct {
	Type       string `xml:"type,attr,omitempty"`
	Title      string `xml:"title,omitempty"`
	SubTitle   string `xml:"subTitle,omitempty"`
	PartNumber string `xml:"partNumber,omitempty"`
	PartName   string `xml:"partName,omitempty"`
}

type Writer

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

Writer converts records and writes them into a <modsCollection>. Close must be called to emit the closing tag.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter returns a Writer that writes a MODS collection to w.

func (*Writer) Close

func (wr *Writer) Close() error

Close writes the closing </modsCollection> tag.

func (*Writer) Write

func (wr *Writer) Write(r *codex.Record) error

Write converts one record and writes its <mods> element within the collection.

Jump to

Keyboard shortcuts

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