eulxml.xmlmap.mods - Metadata Object Description Schema (MODS)

General Information

The Metadata Object Description Standard, or MODS is a schema developed and maintained by the Library of Congress for bibliographic records.

This module defines classes to handle common use cases for MODS metadata, rooted in the MODSv34 object. It is not a complete mapping, though it will likely grow closer to one as development progresses according to user needs.

Root Classes: MODS and Friends

class eulxml.xmlmap.mods.MODS(node=None, context=None, **kwargs)

Top-level XmlObject for a MODS metadata record. Inherits all standard top-level MODS fields from BaseMods and adds a mapping for RelatedItem.

ROOT_NAME = 'mods'
ROOT_NAMESPACES = {'mods': 'http://www.loc.gov/mods/v3'}
ROOT_NS = 'http://www.loc.gov/mods/v3'
XSD_SCHEMA = 'http://www.loc.gov/standards/mods/v3/mods-3-4.xsd'
abstract = <eulxml.xmlmap.fields.NodeField>
access_conditions = <eulxml.xmlmap.fields.NodeListField>
create_abstract(xmlobject)
create_name(xmlobject)
create_note(xmlobject)
create_origin_info(xmlobject)
create_physical_description(xmlobject)
create_record_info(xmlobject)
create_title_info(xmlobject)
genres = <eulxml.xmlmap.fields.NodeListField>
id = <eulxml.xmlmap.fields.StringField>
identifiers = <eulxml.xmlmap.fields.NodeListField>
is_empty()

Returns True if the root node contains no child elements, no attributes, and no text. Returns False if any are present.

is_valid()

Determine if the current document is valid as far as we can determine. If there is a schema associated, check for schema validity. Otherwise, return True.

Return type:boolean
languages = <eulxml.xmlmap.fields.NodeListField>
location = <eulxml.xmlmap.fields.StringField>
locations = <eulxml.xmlmap.fields.NodeListField>
name = <eulxml.xmlmap.fields.NodeField>
names = <eulxml.xmlmap.fields.NodeListField>
node = None
note = <eulxml.xmlmap.fields.NodeField>
notes = <eulxml.xmlmap.fields.NodeListField>
origin_info = <eulxml.xmlmap.fields.NodeField>
parts = <eulxml.xmlmap.fields.NodeListField>
physical_description = <eulxml.xmlmap.fields.NodeField>
record_info = <eulxml.xmlmap.fields.NodeField>
related_items = <eulxml.xmlmap.fields.NodeListField>
resource_type = <eulxml.xmlmap.fields.StringField>
schema_valid()

Determine if the current document is schema-valid according to the configured XSD Schema associated with this instance of XmlObject.

Return type:boolean
Raises:Exception if no XSD schema is defined for this XmlObject instance
schema_validate = True
schema_validation_errors()

Retrieve any validation errors that occured during schema validation done via is_valid().

Returns:a list of lxml.etree._LogEntry instances
Raises:Exception if no XSD schema is defined for this XmlObject instance
serialize(stream=None, pretty=False)

Serialize the contents of the XmlObject to a stream. Serializes current node only; for the entire XML document, use serializeDocument().

If no stream is specified, returns a string. :param stream: stream or other file-like object to write content to (optional) :param pretty: pretty-print the XML output; boolean, defaults to False :rtype: stream passed in or an instance of cStringIO.StringIO

serializeDocument(stream=None, pretty=False)

Serialize the contents of the entire XML document (including Doctype declaration, if there is one), with an XML declaration, for the current XmlObject to a stream.

If no stream is specified, returns a string. :param stream: stream or other file-like object to write content to (optional) :param pretty: pretty-print the XML output; boolean, defaults to False :rtype: stream passed in or an instance of cStringIO.StringIO

subjects = <eulxml.xmlmap.fields.NodeListField>
title = <eulxml.xmlmap.fields.StringField>
title_info = <eulxml.xmlmap.fields.NodeField>
title_info_list = <eulxml.xmlmap.fields.NodeListField>
validation_errors()

Return a list of validation errors. Returns an empty list if the xml is schema valid or no schema is defined. If a schema is defined but schema_validate is False, schema validation will be skipped.

Currently only supports schema validation.

Return type:list
xmlschema

A parsed XSD schema instance of lxml.etree.XMLSchema; will be loaded the first time it is requested on any instance of this class if XSD_SCHEMA is set and xmlchema is None. If you wish to load and parse the schema at class definition time, instead of at class instance initialization time, you may want to define your schema in your subclass like this:

XSD_SCHEMA = "http://www.openarchives.org/OAI/2.0/oai_dc.xsd"
xmlschema = xmlmap.loadSchema(XSD_SCHEMA)
xsl_transform(filename=None, xsl=None, return_type=None, **params)

Run an xslt transform on the contents of the XmlObject.

XSLT can be passed in as an XSLT object generated by load_xslt() or as filename or string. If a params dictionary is specified, its items will be passed as parameters to the XSL transformation, and any string values will automatically be encoded as XSL string parameters.

Note

If XSL is being used multiple times, it is recommended to use :meth`:load_xslt` to load and compile the XSLT once.

Parameters:
  • filename – xslt filename (optional, one of file and xsl is required)
  • xsl – xslt as string OR compiled XSLT object as returned by load_xslt() (optional)
  • return_type – type of object to return; optional, defaults to XmlObject; specify unicode or string for text output
Returns:

an instance of XmlObject or the return_type specified

class eulxml.xmlmap.mods.MODSv34(node=None, context=None, **kwargs)

XmlObject for MODS version 3.4. Currently consists of all the same fields as MODS, but loads the MODS version 3.4 schema for validation.

ROOT_NAME = 'mods'
ROOT_NAMESPACES = {'mods': 'http://www.loc.gov/mods/v3'}
ROOT_NS = 'http://www.loc.gov/mods/v3'
XSD_SCHEMA = 'http://www.loc.gov/standards/mods/v3/mods-3-4.xsd'
abstract = <eulxml.xmlmap.fields.NodeField>
access_conditions = <eulxml.xmlmap.fields.NodeListField>
create_abstract(xmlobject)
create_name(xmlobject)
create_note(xmlobject)
create_origin_info(xmlobject)
create_physical_description(xmlobject)
create_record_info(xmlobject)
create_title_info(xmlobject)
genres = <eulxml.xmlmap.fields.NodeListField>
id = <eulxml.xmlmap.fields.StringField>
identifiers = <eulxml.xmlmap.fields.NodeListField>
is_empty()

Returns True if the root node contains no child elements, no attributes, and no text. Returns False if any are present.

is_valid()

Determine if the current document is valid as far as we can determine. If there is a schema associated, check for schema validity. Otherwise, return True.

Return type:boolean
languages = <eulxml.xmlmap.fields.NodeListField>
location = <eulxml.xmlmap.fields.StringField>
locations = <eulxml.xmlmap.fields.NodeListField>
name = <eulxml.xmlmap.fields.NodeField>
names = <eulxml.xmlmap.fields.NodeListField>
node = None
note = <eulxml.xmlmap.fields.NodeField>
notes = <eulxml.xmlmap.fields.NodeListField>
origin_info = <eulxml.xmlmap.fields.NodeField>
parts = <eulxml.xmlmap.fields.NodeListField>
physical_description = <eulxml.xmlmap.fields.NodeField>
record_info = <eulxml.xmlmap.fields.NodeField>
related_items = <eulxml.xmlmap.fields.NodeListField>
resource_type = <eulxml.xmlmap.fields.StringField>
schema_valid()

Determine if the current document is schema-valid according to the configured XSD Schema associated with this instance of XmlObject.

Return type:boolean
Raises:Exception if no XSD schema is defined for this XmlObject instance
schema_validate = True
schema_validation_errors()

Retrieve any validation errors that occured during schema validation done via is_valid().

Returns:a list of lxml.etree._LogEntry instances
Raises:Exception if no XSD schema is defined for this XmlObject instance
serialize(stream=None, pretty=False)

Serialize the contents of the XmlObject to a stream. Serializes current node only; for the entire XML document, use serializeDocument().

If no stream is specified, returns a string. :param stream: stream or other file-like object to write content to (optional) :param pretty: pretty-print the XML output; boolean, defaults to False :rtype: stream passed in or an instance of cStringIO.StringIO

serializeDocument(stream=None, pretty=False)

Serialize the contents of the entire XML document (including Doctype declaration, if there is one), with an XML declaration, for the current XmlObject to a stream.

If no stream is specified, returns a string. :param stream: stream or other file-like object to write content to (optional) :param pretty: pretty-print the XML output; boolean, defaults to False :rtype: stream passed in or an instance of cStringIO.StringIO

subjects = <eulxml.xmlmap.fields.NodeListField>
title = <eulxml.xmlmap.fields.StringField>
title_info = <eulxml.xmlmap.fields.NodeField>
title_info_list = <eulxml.xmlmap.fields.NodeListField>
validation_errors()

Return a list of validation errors. Returns an empty list if the xml is schema valid or no schema is defined. If a schema is defined but schema_validate is False, schema validation will be skipped.

Currently only supports schema validation.

Return type:list
xmlschema

A parsed XSD schema instance of lxml.etree.XMLSchema; will be loaded the first time it is requested on any instance of this class if XSD_SCHEMA is set and xmlchema is None. If you wish to load and parse the schema at class definition time, instead of at class instance initialization time, you may want to define your schema in your subclass like this:

XSD_SCHEMA = "http://www.openarchives.org/OAI/2.0/oai_dc.xsd"
xmlschema = xmlmap.loadSchema(XSD_SCHEMA)
xsl_transform(filename=None, xsl=None, return_type=None, **params)

Run an xslt transform on the contents of the XmlObject.

XSLT can be passed in as an XSLT object generated by load_xslt() or as filename or string. If a params dictionary is specified, its items will be passed as parameters to the XSL transformation, and any string values will automatically be encoded as XSL string parameters.

Note

If XSL is being used multiple times, it is recommended to use :meth`:load_xslt` to load and compile the XSLT once.

Parameters:
  • filename – xslt filename (optional, one of file and xsl is required)
  • xsl – xslt as string OR compiled XSLT object as returned by load_xslt() (optional)
  • return_type – type of object to return; optional, defaults to XmlObject; specify unicode or string for text output
Returns:

an instance of XmlObject or the return_type specified

Title Info

MODS titleInfo

class eulxml.xmlmap.mods.TitleInfo(node=None, context=None, **kwargs)
ROOT_NAME = 'titleInfo'
is_empty()

Returns True if all titleInfo subfields are not set or empty; returns False if any of the fields are not empty.

label = <eulxml.xmlmap.fields.StringField>
non_sort = <eulxml.xmlmap.fields.StringField>
part_name = <eulxml.xmlmap.fields.StringField>
part_number = <eulxml.xmlmap.fields.StringField>
subtitle = <eulxml.xmlmap.fields.StringField>
title = <eulxml.xmlmap.fields.StringField>
type = <eulxml.xmlmap.fields.StringField>

Name

MODS name

class eulxml.xmlmap.mods.Name(node=None, context=None, **kwargs)

XmlObject for MODS name

ROOT_NAME = 'name'
affiliation = <eulxml.xmlmap.fields.StringField>
authority = <eulxml.xmlmap.fields.StringField>
display_form = <eulxml.xmlmap.fields.StringField>
id = <eulxml.xmlmap.fields.StringField>
name_parts = <eulxml.xmlmap.fields.NodeListField>
roles = <eulxml.xmlmap.fields.NodeListField>
type = <eulxml.xmlmap.fields.StringField>
class eulxml.xmlmap.mods.NamePart(node=None, context=None, **kwargs)

XmlObject for MODS namePart

ROOT_NAME = 'namePart'
text = <eulxml.xmlmap.fields.StringField>
type = <eulxml.xmlmap.fields.StringField>
class eulxml.xmlmap.mods.Role(node=None, context=None, **kwargs)

XmlObject for MODS role

ROOT_NAME = 'role'
authority = <eulxml.xmlmap.fields.StringField>
text = <eulxml.xmlmap.fields.StringField>
type = <eulxml.xmlmap.fields.StringField>

Genre

MODS genre

class eulxml.xmlmap.mods.Genre(node=None, context=None, **kwargs)
ROOT_NAME = 'genre'
authority = <eulxml.xmlmap.fields.StringField>
text = <eulxml.xmlmap.fields.StringField>

Origin Info

MODS originInfo

class eulxml.xmlmap.mods.OriginInfo(node=None, context=None, **kwargs)

XmlObject for MODS originInfo element (incomplete)

ROOT_NAME = 'originInfo'
captured = <eulxml.xmlmap.fields.NodeListField>
copyright = <eulxml.xmlmap.fields.NodeListField>
created = <eulxml.xmlmap.fields.NodeListField>
is_empty()

Returns True if all child date elements present are empty and other nodes are not set. Returns False if any child date elements are not empty or other nodes are set.

issued = <eulxml.xmlmap.fields.NodeListField>
modified = <eulxml.xmlmap.fields.NodeListField>
other = <eulxml.xmlmap.fields.NodeListField>
publisher = <eulxml.xmlmap.fields.StringField>
valid = <eulxml.xmlmap.fields.NodeListField>
class eulxml.xmlmap.mods.DateCreated(node=None, context=None, **kwargs)
ROOT_NAME = 'dateCreated'
class eulxml.xmlmap.mods.DateIssued(node=None, context=None, **kwargs)
ROOT_NAME = 'dateIssued'

Language

MODS language

class eulxml.xmlmap.mods.Language(node=None, context=None, **kwargs)
ROOT_NAME = 'language'
terms = <eulxml.xmlmap.fields.NodeListField>
class eulxml.xmlmap.mods.LanguageTerm(node=None, context=None, **kwargs)
ROOT_NAME = 'languageTerm'
authority = <eulxml.xmlmap.fields.StringField>
text = <eulxml.xmlmap.fields.StringField>
type = <eulxml.xmlmap.fields.StringField>

Physical Description

MODS physicalDescription

class eulxml.xmlmap.mods.PhysicalDescription(node=None, context=None, **kwargs)
ROOT_NAME = 'physicalDescription'
extent = <eulxml.xmlmap.fields.StringField>
media_type = <eulxml.xmlmap.fields.StringField>

Abstract

MODS abstract

class eulxml.xmlmap.mods.Abstract(node=None, context=None, **kwargs)
ROOT_NAME = 'abstract'
label = <eulxml.xmlmap.fields.StringField>
text = <eulxml.xmlmap.fields.StringField>
type = <eulxml.xmlmap.fields.StringField>

Note

MODS note

class eulxml.xmlmap.mods.Note(node=None, context=None, **kwargs)

XmlObject for MODS note element

ROOT_NAME = 'note'
label = <eulxml.xmlmap.fields.StringField>
text = <eulxml.xmlmap.fields.StringField>
type = <eulxml.xmlmap.fields.StringField>
class eulxml.xmlmap.mods.TypedNote(node=None, context=None, **kwargs)

Extends Note to modify is_empty() behavior– considered empty when a type attribute is set without any text.

Subject

MODS subject

class eulxml.xmlmap.mods.Subject(node=None, context=None, **kwargs)
ROOT_NAME = 'subject'
authority = <eulxml.xmlmap.fields.StringField>
create_name(xmlobject)
geographic = <eulxml.xmlmap.fields.StringField>
id = <eulxml.xmlmap.fields.StringField>
name = <eulxml.xmlmap.fields.NodeField>
title = <eulxml.xmlmap.fields.StringField>
topic = <eulxml.xmlmap.fields.StringField>

Identifer

MODS identifier

class eulxml.xmlmap.mods.Identifier(node=None, context=None, **kwargs)

XmlObject for MODS identifier

ROOT_NAME = 'identifier'
label = <eulxml.xmlmap.fields.StringField>
text = <eulxml.xmlmap.fields.StringField>
type = <eulxml.xmlmap.fields.StringField>

Location

MODS location

class eulxml.xmlmap.mods.Location(node=None, context=None, **kwargs)
ROOT_NAME = 'location'
physical = <eulxml.xmlmap.fields.StringField>
url = <eulxml.xmlmap.fields.StringField>

Access Condition

MODS accessCondition

class eulxml.xmlmap.mods.AccessCondition(node=None, context=None, **kwargs)

XmlObject for MODS accessCondition

ROOT_NAME = 'accessCondition'
text = <eulxml.xmlmap.fields.StringField>
type = <eulxml.xmlmap.fields.StringField>

Part

MODS part

class eulxml.xmlmap.mods.Part(node=None, context=None, **kwargs)
ROOT_NAME = 'part'
create_extent(xmlobject)
details = <eulxml.xmlmap.fields.NodeListField>
extent = <eulxml.xmlmap.fields.NodeField>
is_empty()

Returns True if details, extent, and type are not set or return True for is_empty; returns False if any of the fields are not empty.

type = <eulxml.xmlmap.fields.StringField>
class eulxml.xmlmap.mods.PartDetail(node=None, context=None, **kwargs)
ROOT_NAME = 'detail'
is_empty()

Returns False if no number value is set; returns True if any number value is set. Type attribute is ignored for determining whether or not this node should be considered empty.

number = <eulxml.xmlmap.fields.StringField>
type = <eulxml.xmlmap.fields.StringField>
class eulxml.xmlmap.mods.PartExtent(node=None, context=None, **kwargs)
ROOT_NAME = 'extent'
end = <eulxml.xmlmap.fields.StringField>
is_empty()

Returns False if no extent value is set; returns True if any extent value is set. Unit attribute is ignored for determining whether or not this node should be considered empty.

start = <eulxml.xmlmap.fields.StringField>
total = <eulxml.xmlmap.fields.StringField>
unit = <eulxml.xmlmap.fields.StringField>

Record Info

MODS recordInfo

class eulxml.xmlmap.mods.RecordInfo(node=None, context=None, **kwargs)
ROOT_NAME = 'recordInfo'
change_date = <eulxml.xmlmap.fields.StringField>
creation_date = <eulxml.xmlmap.fields.StringField>
record_id = <eulxml.xmlmap.fields.StringField>
record_origin = <eulxml.xmlmap.fields.StringField>