Home > Hacking Invenio > BibRecord Internals |
BibRecord library offer a whole set of API function to handle record metadata.
In order to work with bibrecord library you first need to have available a record representation.
If you have a MARCXML representation of the record to be handled, you can use the create_record function to obtain a bibrecord internal representation:
from invenio.bibrecord.bibrecord import create_record record = create_record(marcxml)[0]
If you want to handle a record stored in the system and you know the record ID, then you can easily exploit Invenio search_engine API to obtain the corresponding marcxml:
from invenio.bibrecord.bibrecord import create_record from invenio.websearch.search_engine import print_record marcxml = print_record(rec_id, 'xm') record = create_record(marcxml)[0]
Having an internal representation of a record you can manipulate it by means of bibrecord functions like record_get_field_instances, record_has_field, record_add_field, record_delete_field, record_delete_subfield, record_add_or_modify_subfield, record_add_subfield, record_does_field_exist, record_filter_fields, record_replace_in_subfields, record_get_field_value, record_get_field_values...
At the end, if you want the MARCXML representation of the record you can use record_xml_output:
from invenio.bibrecord.bibrecord import create_record from invenio.websearch.search_engine import print_record marcxml = print_record(rec_id, 'xm') record = create_record(marcxml)[0] ... manipulation ... new_marcxml = record_xml_output(record)
In order to write back such a record into the system you should use the BibUpload utility.
Please referer to bibrecord.py for a complete and up-to-date description of the API.
As always, a good entry point to the bibrecord library and its record structure manipulating functions
is to read the unit test cases that are located in bibrecord_tests.py
and bibupload_regression_tests.py
.