YAZ  5.23.1
Data Structures | Enumerations | Functions | Variables
marcdisp.c File Reference

Implements MARC conversion utilities. More...

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <yaz/marcdisp.h>
#include <yaz/wrbuf.h>
#include <yaz/yaz-util.h>
#include <yaz/nmem_xml.h>
#include <yaz/snprintf.h>
#include <libxml/parser.h>
#include <libxml/tree.h>

Go to the source code of this file.

Data Structures

struct  yaz_marc_datafield
 represents a data field More...
 
struct  yaz_marc_controlfield
 represents a control field More...
 
struct  yaz_marc_comment
 a comment node More...
 
struct  yaz_marc_node
 MARC node. More...
 
struct  yaz_marc_subfield
 represents a subfield More...
 
struct  yaz_marc_t_
 the internals of a yaz_marc_t handle More...
 

Enumerations

enum  yaz_collection_state { no_collection, collection_first, collection_second }
 
enum  YAZ_MARC_NODE_TYPE { YAZ_MARC_DATAFIELD, YAZ_MARC_CONTROLFIELD, YAZ_MARC_COMMENT, YAZ_MARC_LEADER }
 node types for yaz_marc_node More...
 

Functions

yaz_marc_t yaz_marc_create (void)
 construct yaz_marc_t handle More...
 
void yaz_marc_destroy (yaz_marc_t mt)
 destroy yaz_marc_t handle More...
 
NMEM yaz_marc_get_nmem (yaz_marc_t mt)
 returns memory for MARC handle More...
 
static void marc_iconv_reset (yaz_marc_t mt, WRBUF wr)
 
static int marc_exec_leader (const char *leader_spec, char *leader, size_t size)
 
static int yaz_marc_write_xml_turbo_xml (yaz_marc_t mt, xmlNode **root_ptr, const char *ns, const char *format, const char *type)
 
static struct yaz_marc_nodeyaz_marc_add_node (yaz_marc_t mt)
 
void yaz_marc_add_controlfield_xml (yaz_marc_t mt, const xmlNode *ptr_tag, const xmlNode *ptr_data)
 adds controlfield to MARC structure using xml Nodes More...
 
void yaz_marc_add_controlfield_xml2 (yaz_marc_t mt, char *tag, const xmlNode *ptr_data)
 adds controlfield to MARC structure using xml Nodes for data More...
 
void yaz_marc_add_comment (yaz_marc_t mt, char *comment)
 adds MARC comment string More...
 
void yaz_marc_cprintf (yaz_marc_t mt, const char *fmt,...)
 adds MARC annotation - printf interface More...
 
int yaz_marc_get_debug (yaz_marc_t mt)
 gets debug level for MARC system More...
 
void yaz_marc_add_leader (yaz_marc_t mt, const char *leader, size_t leader_len)
 
void yaz_marc_add_controlfield (yaz_marc_t mt, const char *tag, const char *data, size_t data_len)
 adds controlfield to MARC structure More...
 
void yaz_marc_add_datafield (yaz_marc_t mt, const char *tag, const char *indicator, size_t indicator_len)
 adds datafield to MARC structure using strings More...
 
static int element_name_append_attribute_value (yaz_marc_t mt, WRBUF buffer, const char *attribute_name, char *code_data, size_t code_len)
 adds a attribute value to the element name if it is plain chars More...
 
void yaz_marc_add_datafield_xml (yaz_marc_t mt, const xmlNode *ptr_tag, const char *indicator, size_t indicator_len)
 adds datafield to MARC structure using xml Nodes More...
 
void yaz_marc_add_datafield_xml2 (yaz_marc_t mt, char *tag_value, char *indicators)
 adds datafield to MARC structure using xml Nodes More...
 
void yaz_marc_datafield_set_indicators (struct yaz_marc_node *n, char *indicator)
 
void yaz_marc_add_subfield (yaz_marc_t mt, const char *code_data, size_t code_data_len)
 adds subfield to MARC structure More...
 
static void check_ascii (yaz_marc_t mt, char *leader, int offset, int ch_default)
 
void yaz_marc_set_leader (yaz_marc_t mt, const char *leader_c, int *indicator_length, int *identifier_length, int *base_address, int *length_data_entry, int *length_starting, int *length_implementation)
 sets leader, validates it, and returns important values More...
 
void yaz_marc_subfield_str (yaz_marc_t mt, const char *s)
 
void yaz_marc_endline_str (yaz_marc_t mt, const char *s)
 
static size_t cdata_one_character (yaz_marc_t mt, const char *buf)
 
size_t yaz_marc_sizeof_char (yaz_marc_t mt, const char *buf)
 
void yaz_marc_reset (yaz_marc_t mt)
 clears memory and MARC record More...
 
int yaz_marc_write_check (yaz_marc_t mt, WRBUF wr)
 
static size_t get_subfield_len (yaz_marc_t mt, const char *data, int identifier_length)
 
int yaz_marc_write_line (yaz_marc_t mt, WRBUF wr)
 writes record in line format More...
 
int yaz_marc_write_trailer (yaz_marc_t mt, WRBUF wr)
 flushes records More...
 
void yaz_marc_enable_collection (yaz_marc_t mt)
 enables record collection output More...
 
int yaz_marc_write_mode (yaz_marc_t mt, WRBUF wr)
 writes record in mode - given by yaz_marc_xml mode More...
 
static int yaz_marc_write_marcxml_wrbuf (yaz_marc_t mt, WRBUF wr, const char *ns, const char *format, const char *type, int turbo)
 common MARC XML/Xchange/turbomarc writer More...
 
static int yaz_marc_write_marcxml_ns (yaz_marc_t mt, WRBUF wr, const char *ns, const char *format, const char *type, int turbo)
 
int yaz_marc_write_marcxml (yaz_marc_t mt, WRBUF wr)
 writes record in MARCXML format More...
 
int yaz_marc_write_turbomarc (yaz_marc_t mt, WRBUF wr)
 writes record in TurboMARC format More...
 
int yaz_marc_write_marcxchange (yaz_marc_t mt, WRBUF wr, const char *format, const char *type)
 writes record in MarcXchange XML (ISO25577) More...
 
static void write_xml_indicator (yaz_marc_t mt, struct yaz_marc_node *n, xmlNode *ptr, int turbo)
 
static void add_marc_datafield_turbo_xml (yaz_marc_t mt, struct yaz_marc_node *n, xmlNode *record_ptr, xmlNsPtr ns_record, WRBUF wr_cdata, int identifier_length)
 
int yaz_marc_write_xml (yaz_marc_t mt, xmlNode **root_ptr, const char *ns, const char *format, const char *type)
 writes MARC record as libxml2 tree More...
 
int yaz_marc_write_iso2709 (yaz_marc_t mt, WRBUF wr)
 writes record in ISO2709 format More...
 
int yaz_marc_write_json (yaz_marc_t mt, WRBUF w)
 writes MARC record in JSON represenation More...
 
int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf, int bsize, WRBUF wr)
 decodes ISO2709/MARC buffer and stores result in WRBUF More...
 
int yaz_marc_decode_buf (yaz_marc_t mt, const char *buf, int bsize, const char **result, size_t *rsize)
 decodes ISO2709 buffer using straight buffers More...
 
void yaz_marc_xml (yaz_marc_t mt, int xmlmode)
 set XML mode YAZ_MARC_LINE, YAZ_MARCXML, YAZ_MARC_ISO2709 .. More...
 
void yaz_marc_debug (yaz_marc_t mt, int level)
 set debug level More...
 
void yaz_marc_iconv (yaz_marc_t mt, yaz_iconv_t cd)
 set iconv handle for character set conversion More...
 
yaz_iconv_t yaz_marc_get_iconv (yaz_marc_t mt)
 supply iconv handle for character set conversion More...
 
void yaz_marc_modify_leader (yaz_marc_t mt, size_t off, const char *str)
 modifies part of the MARC leader More...
 
int yaz_marc_leader_spec (yaz_marc_t mt, const char *leader_spec)
 sets leader spec (for modifying bytes in 24 byte leader) More...
 
int yaz_marc_decode_formatstr (const char *arg)
 Converts MARC format type to format type(YAZ_MARC_..) More...
 
void yaz_marc_write_using_libxml2 (yaz_marc_t mt, int enable)
 Enables or disables writing of MARC XML records using Libxml2. More...
 
int yaz_marc_check_marc21_coding (const char *charset, const char *marc_buf, int sz)
 check if MARC21 is UTF-8 encoded More...
 

Variables

static const char * record_name [2] = { "record", "r"}
 
static const char * leader_name [2] = { "leader", "l"}
 
static const char * controlfield_name [2] = { "controlfield", "c"}
 
static const char * datafield_name [2] = { "datafield", "d"}
 
static const char * indicator_name [2] = { "ind", "i"}
 
static const char * subfield_name [2] = { "subfield", "s"}
 

Detailed Description

Implements MARC conversion utilities.

Definition in file marcdisp.c.

Enumeration Type Documentation

Enumerator
no_collection 
collection_first 
collection_second 

Definition at line 34 of file marcdisp.c.

node types for yaz_marc_node

Enumerator
YAZ_MARC_DATAFIELD 
YAZ_MARC_CONTROLFIELD 
YAZ_MARC_COMMENT 
YAZ_MARC_LEADER 

Definition at line 41 of file marcdisp.c.

Function Documentation

static void add_marc_datafield_turbo_xml ( yaz_marc_t  mt,
struct yaz_marc_node n,
xmlNode *  record_ptr,
xmlNsPtr  ns_record,
WRBUF  wr_cdata,
int  identifier_length 
)
static
static size_t cdata_one_character ( yaz_marc_t  mt,
const char *  buf 
)
static
static void check_ascii ( yaz_marc_t  mt,
char *  leader,
int  offset,
int  ch_default 
)
static

Definition at line 344 of file marcdisp.c.

References yaz_marc_cprintf().

Referenced by yaz_marc_set_leader().

static int element_name_append_attribute_value ( yaz_marc_t  mt,
WRBUF  buffer,
const char *  attribute_name,
char *  code_data,
size_t  code_len 
)
static

adds a attribute value to the element name if it is plain chars

If not, and if the attribute name is not null, it will append a attribute element with the value if attribute name is null it will return a non-zero value meaning it couldnt handle the value.

Definition at line 253 of file marcdisp.c.

References yaz_marc_t_::iconv_cd, wrbuf_iconv_write_cdata(), and wrbuf_printf().

Referenced by add_marc_datafield_turbo_xml(), and yaz_marc_write_marcxml_wrbuf().

static size_t get_subfield_len ( yaz_marc_t  mt,
const char *  data,
int  identifier_length 
)
static
static int marc_exec_leader ( const char *  leader_spec,
char *  leader,
size_t  size 
)
static

Definition at line 1421 of file marcdisp.c.

Referenced by marc_iconv_reset(), yaz_marc_add_leader(), and yaz_marc_leader_spec().

static void marc_iconv_reset ( yaz_marc_t  mt,
WRBUF  wr 
)
static
static void write_xml_indicator ( yaz_marc_t  mt,
struct yaz_marc_node n,
xmlNode *  ptr,
int  turbo 
)
static
void yaz_marc_add_comment ( yaz_marc_t  mt,
char *  comment 
)

adds MARC comment string

Parameters
mthandle
commentcomment to be added)

Definition at line 181 of file marcdisp.c.

References yaz_marc_node::comment, yaz_marc_t_::nmem, nmem_strdup(), yaz_marc_node::u, yaz_marc_node::which, yaz_marc_add_node(), and YAZ_MARC_COMMENT.

Referenced by yaz_marc_add_controlfield(), yaz_marc_add_subfield(), and yaz_marc_cprintf().

void yaz_marc_add_controlfield ( yaz_marc_t  mt,
const char *  tag,
const char *  data,
size_t  data_len 
)

adds controlfield to MARC structure

Parameters
mthandle
tag(e.g. "001"
datavalue for this tag
data_lenlength of data

Definition at line 212 of file marcdisp.c.

References yaz_marc_node::controlfield, yaz_marc_controlfield::data, yaz_marc_t_::debug, yaz_marc_t_::nmem, nmem_strdup(), nmem_strdupn(), yaz_marc_controlfield::tag, yaz_marc_node::u, yaz_marc_node::which, yaz_marc_add_comment(), yaz_marc_add_node(), and YAZ_MARC_CONTROLFIELD.

Referenced by parse_field(), yaz_marc_read_iso2709(), and yaz_marc_read_line().

void yaz_marc_add_controlfield_xml ( yaz_marc_t  mt,
const xmlNode *  ptr_tag,
const xmlNode *  ptr_data 
)

adds controlfield to MARC structure using xml Nodes

Parameters
mthandle
ptr_tagvalue of tag (TEXT xmlNode)
ptr_datavalue of data (TEXT xmlNode)

Definition at line 160 of file marcdisp.c.

References yaz_marc_node::controlfield, yaz_marc_controlfield::data, yaz_marc_t_::nmem, nmem_text_node_cdata(), yaz_marc_controlfield::tag, yaz_marc_node::u, yaz_marc_node::which, yaz_marc_add_node(), and YAZ_MARC_CONTROLFIELD.

Referenced by yaz_marc_read_xml_fields().

void yaz_marc_add_controlfield_xml2 ( yaz_marc_t  mt,
char *  tag,
const xmlNode *  ptr_data 
)

adds controlfield to MARC structure using xml Nodes for data

Parameters
mthandle
tagstring tag
ptr_datavalue of data (TEXT xmlNode)

Definition at line 169 of file marcdisp.c.

References yaz_marc_node::controlfield, yaz_marc_controlfield::data, yaz_marc_t_::nmem, nmem_text_node_cdata(), yaz_marc_datafield::tag, yaz_marc_controlfield::tag, yaz_marc_node::u, yaz_marc_node::which, yaz_marc_add_node(), and YAZ_MARC_CONTROLFIELD.

Referenced by yaz_marc_read_turbo_xml_fields().

void yaz_marc_add_datafield ( yaz_marc_t  mt,
const char *  tag,
const char *  indicator,
size_t  indicator_len 
)

adds datafield to MARC structure using strings

Parameters
mthandle
tagvalue of tag as string
indicatorindicator string
indicator_lenlength of indicator string

Definition at line 233 of file marcdisp.c.

References yaz_marc_node::datafield, yaz_marc_datafield::indicator, yaz_marc_t_::nmem, nmem_strdup(), nmem_strdupn(), yaz_marc_t_::subfield_pp, yaz_marc_datafield::subfields, yaz_marc_datafield::tag, yaz_marc_node::u, yaz_marc_node::which, yaz_marc_add_node(), and YAZ_MARC_DATAFIELD.

Referenced by parse_field(), yaz_marc_read_iso2709(), and yaz_marc_read_line().

void yaz_marc_add_datafield_xml ( yaz_marc_t  mt,
const xmlNode *  ptr_tag,
const char *  indicator,
size_t  indicator_len 
)

adds datafield to MARC structure using xml Nodes

Parameters
mthandle
ptr_tagvalue of tag (TEXT xmlNode)
indicatorindicator string
indicator_lenlength of indicator string

Definition at line 284 of file marcdisp.c.

References yaz_marc_node::datafield, yaz_marc_datafield::indicator, yaz_marc_t_::nmem, nmem_strdup(), nmem_text_node_cdata(), yaz_marc_t_::subfield_pp, yaz_marc_datafield::subfields, yaz_marc_datafield::tag, yaz_marc_node::u, yaz_marc_node::which, yaz_marc_add_node(), and YAZ_MARC_DATAFIELD.

Referenced by yaz_marc_read_xml_fields().

void yaz_marc_add_datafield_xml2 ( yaz_marc_t  mt,
char *  tag_value,
char *  indicators 
)

adds datafield to MARC structure using xml Nodes

Parameters
mthandle
tag_valuestring value (pointer copied verbatim, not strdupped)
indicatorsindicator string ; pointer copied verbatim; not strdupped

Definition at line 297 of file marcdisp.c.

References yaz_marc_node::datafield, yaz_marc_datafield::indicator, yaz_marc_t_::subfield_pp, yaz_marc_datafield::subfields, yaz_marc_datafield::tag, yaz_marc_node::u, yaz_marc_node::which, yaz_marc_add_node(), and YAZ_MARC_DATAFIELD.

Referenced by yaz_marc_read_turbo_xml_fields().

void yaz_marc_add_leader ( yaz_marc_t  mt,
const char *  leader,
size_t  leader_len 
)
static struct yaz_marc_node* yaz_marc_add_node ( yaz_marc_t  mt)
static
void yaz_marc_add_subfield ( yaz_marc_t  mt,
const char *  code_data,
size_t  code_data_len 
)

adds subfield to MARC structure

Parameters
mthandle
code_datacode data buffer
code_data_lenlength of code data

Definition at line 316 of file marcdisp.c.

References yaz_marc_subfield::code_data, yaz_marc_t_::debug, yaz_marc_subfield::next, yaz_marc_t_::nmem, nmem_malloc(), nmem_strdupn(), yaz_marc_t_::subfield_pp, and yaz_marc_add_comment().

Referenced by parse_subfields(), yaz_marc_read_iso2709(), yaz_marc_read_line(), yaz_marc_read_turbo_xml_subfields(), and yaz_marc_read_xml_subfields().

int yaz_marc_check_marc21_coding ( const char *  charset,
const char *  marc_buf,
int  sz 
)

check if MARC21 is UTF-8 encoded

Parameters
charsetthat is given by user
marc_bufISO2709 buf
szISO2709 size
Return values
1is probably UTF-8
0is not UTF-8

Definition at line 1487 of file marcdisp.c.

References yaz_matchstr().

Referenced by convert_marc(), iconv_create_charset(), and yaz_opac_check_marc21_coding().

void yaz_marc_cprintf ( yaz_marc_t  mt,
const char *  fmt,
  ... 
)
yaz_marc_t yaz_marc_create ( void  )
void yaz_marc_datafield_set_indicators ( struct yaz_marc_node n,
char *  indicator 
)
void yaz_marc_debug ( yaz_marc_t  mt,
int  level 
)

set debug level

Parameters
mthandle
levellevel, where 0=lowest, 1 more debug, 2 even more

Definition at line 1378 of file marcdisp.c.

References yaz_marc_t_::debug.

int yaz_marc_decode_buf ( yaz_marc_t  mt,
const char *  buf,
int  bsize,
const char **  result,
size_t *  rsize 
)

decodes ISO2709 buffer using straight buffers

Parameters
mtmarc handle
bufinput buffer
bsizesize of buffer or (-1 if "any size")
resultresult to be stored here
rsizesize of result (memory "owned" by yaz_marc_mt handle)

Decodes MARC in buf of size bsize. On success, result in *result with size *rsize. Returns -1 on error, or size of input record (>0) if OK

Definition at line 1359 of file marcdisp.c.

References yaz_marc_t_::m_wr, wrbuf_cstr(), wrbuf_len, wrbuf_rewind(), and yaz_marc_decode_wrbuf().

int yaz_marc_decode_formatstr ( const char *  arg)

Converts MARC format type to format type(YAZ_MARC_..)

Parameters
argstring
Return values
-1unknown format (bad arg)
>=0 OK (one of YAZ_MARC - values)

Definition at line 1464 of file marcdisp.c.

References YAZ_MARC_ISO2709, YAZ_MARC_JSON, YAZ_MARC_LINE, YAZ_MARC_MARCXML, YAZ_MARC_TURBOMARC, and YAZ_MARC_XCHANGE.

int yaz_marc_decode_wrbuf ( yaz_marc_t  mt,
const char *  buf,
int  bsize,
WRBUF  wrbuf 
)

decodes ISO2709/MARC buffer and stores result in WRBUF

Parameters
mthandle
bufinput buffer
bsizesize of buffer (-1 if "any size")
wrbufWRBUF for output

Decodes MARC in buf of size bsize. On success, result in wrbuf Returns -1 on error, or size of input record (>0) if OK

Definition at line 1348 of file marcdisp.c.

References yaz_marc_read_iso2709(), and yaz_marc_write_mode().

Referenced by dummy_json_record(), dummy_xml_record(), return_marc_record(), yaz_marc_decode_buf(), and yaz_opac_decode_wrbuf2().

void yaz_marc_destroy ( yaz_marc_t  mt)
void yaz_marc_enable_collection ( yaz_marc_t  mt)

enables record collection output

Parameters
mthandle

Definition at line 618 of file marcdisp.c.

References collection_first, and yaz_marc_t_::enable_collection.

void yaz_marc_endline_str ( yaz_marc_t  mt,
const char *  s 
)

Definition at line 438 of file marcdisp.c.

References yaz_marc_t_::endline_str.

int yaz_marc_get_debug ( yaz_marc_t  mt)

gets debug level for MARC system

Parameters
mthandle

Definition at line 199 of file marcdisp.c.

References yaz_marc_t_::debug.

Referenced by yaz_marc_read_iso2709().

yaz_iconv_t yaz_marc_get_iconv ( yaz_marc_t  mt)

supply iconv handle for character set conversion

Definition at line 1389 of file marcdisp.c.

References yaz_marc_t_::iconv_cd.

Referenced by yaz_opac_decode_wrbuf2().

NMEM yaz_marc_get_nmem ( yaz_marc_t  mt)

returns memory for MARC handle

Parameters
mthandle
Return values
NMEMhandle for MARC system

Definition at line 130 of file marcdisp.c.

References yaz_marc_t_::nmem.

Referenced by yaz_marc_read_turbo_xml_fields(), yaz_marc_read_turbo_xml_subfields(), yaz_marc_read_xml_subfields(), and yaz_xml_to_opac_ptr().

void yaz_marc_iconv ( yaz_marc_t  mt,
yaz_iconv_t  cd 
)

set iconv handle for character set conversion

Definition at line 1384 of file marcdisp.c.

References yaz_marc_t_::iconv_cd.

Referenced by convert_marc(), return_marc_record(), return_opac_record(), and yaz_record_conv_opac_record().

int yaz_marc_leader_spec ( yaz_marc_t  mt,
const char *  leader_spec 
)

sets leader spec (for modifying bytes in 24 byte leader)

Parameters
mthandle
leader_spec
Return values
0OK
-1ERROR

Spec takes form pos=val,pos=val,... where value is either a number (decimal char value) or a string in 'a', e.g. 9='a'

Definition at line 1407 of file marcdisp.c.

References yaz_marc_t_::leader_spec, marc_exec_leader(), xfree, and xstrdup.

Referenced by convert_marc().

void yaz_marc_modify_leader ( yaz_marc_t  mt,
size_t  off,
const char *  str 
)
void yaz_marc_reset ( yaz_marc_t  mt)

clears memory and MARC record

Parameters
mthandle

Definition at line 483 of file marcdisp.c.

References yaz_marc_t_::nmem, nmem_reset(), yaz_marc_t_::nodes, yaz_marc_t_::nodes_pp, and yaz_marc_t_::subfield_pp.

Referenced by yaz_marc_create(), yaz_marc_read_iso2709(), yaz_marc_read_line(), and yaz_marc_read_xml().

void yaz_marc_set_leader ( yaz_marc_t  mt,
const char *  leader,
int *  indicator_length,
int *  identifier_length,
int *  base_address,
int *  length_data_entry,
int *  length_starting,
int *  length_implementation 
)

sets leader, validates it, and returns important values

Parameters
mthandle
leaderof the 24 byte leader to be set
indicator_lengthindicator length (returned value)
identifier_lengthidentifier length (returned value)
base_addressbase address (returned value)
length_data_entrylength of data entry (returned value)
length_startinglength of starting
length_implementationlength of implementation defined data

Definition at line 356 of file marcdisp.c.

References atoi_n_check(), check_ascii(), yaz_marc_t_::debug, yaz_marc_add_leader(), and yaz_marc_cprintf().

Referenced by yaz_marc_read_iso2709(), yaz_marc_read_json_node(), yaz_marc_read_line(), and yaz_marc_read_xml_leader().

size_t yaz_marc_sizeof_char ( yaz_marc_t  mt,
const char *  buf 
)

Definition at line 478 of file marcdisp.c.

References cdata_one_character().

Referenced by yaz_marc_read_iso2709().

void yaz_marc_subfield_str ( yaz_marc_t  mt,
const char *  s 
)

Definition at line 432 of file marcdisp.c.

References yaz_marc_t_::subfield_str.

int yaz_marc_write_check ( yaz_marc_t  mt,
WRBUF  wr 
)
int yaz_marc_write_iso2709 ( yaz_marc_t  mt,
WRBUF  wrbuf 
)
int yaz_marc_write_json ( yaz_marc_t  mt,
WRBUF  w 
)
int yaz_marc_write_line ( yaz_marc_t  mt,
WRBUF  wrbuf 
)
int yaz_marc_write_marcxchange ( yaz_marc_t  mt,
WRBUF  wrbuf,
const char *  format,
const char *  type 
)

writes record in MarcXchange XML (ISO25577)

Parameters
mthandle
wrbufWRBUF for output
formatrecord format (e.g. "MARC21")
typerecord type (e.g. Bibliographic)
Return values
0OK
-1ERROR

Definition at line 871 of file marcdisp.c.

References yaz_marc_write_marcxml_ns().

Referenced by yaz_marc_write_mode().

int yaz_marc_write_marcxml ( yaz_marc_t  mt,
WRBUF  wrbuf 
)

writes record in MARCXML format

Parameters
mthandle
wrbufWRBUF for output
Return values
0OK
-1ERROR

Sets leader[9]='a' .

Definition at line 850 of file marcdisp.c.

References yaz_marc_t_::leader_spec, yaz_marc_modify_leader(), and yaz_marc_write_marcxml_ns().

Referenced by yaz_marc_write_mode().

static int yaz_marc_write_marcxml_ns ( yaz_marc_t  mt,
WRBUF  wr,
const char *  ns,
const char *  format,
const char *  type,
int  turbo 
)
static
static int yaz_marc_write_marcxml_wrbuf ( yaz_marc_t  mt,
WRBUF  wr,
const char *  ns,
const char *  format,
const char *  type,
int  turbo 
)
static
int yaz_marc_write_mode ( yaz_marc_t  mt,
WRBUF  wrbuf 
)

writes record in mode - given by yaz_marc_xml mode

Parameters
mthandle
wrbufWRBUF for output
Return values
0OK
-1ERROR

This function calls yaz_marc_write_iso2709, yaz_marc_write_marcxml, etc.. depending on mode given by yaz_marc_xml.

Definition at line 623 of file marcdisp.c.

References yaz_marc_t_::output_format, YAZ_MARC_CHECK, YAZ_MARC_ISO2709, YAZ_MARC_JSON, YAZ_MARC_LINE, YAZ_MARC_MARCXML, YAZ_MARC_TURBOMARC, yaz_marc_write_check(), yaz_marc_write_iso2709(), yaz_marc_write_json(), yaz_marc_write_line(), yaz_marc_write_marcxchange(), yaz_marc_write_marcxml(), yaz_marc_write_turbomarc(), and YAZ_MARC_XCHANGE.

Referenced by convert_marc(), and yaz_marc_decode_wrbuf().

int yaz_marc_write_trailer ( yaz_marc_t  mt,
WRBUF  wr 
)

flushes records

Parameters
mthandle
wrWRBUF for output
Return values
0OK
-1ERROR

Definition at line 600 of file marcdisp.c.

References collection_second, yaz_marc_t_::enable_collection, yaz_marc_t_::output_format, wrbuf_printf(), YAZ_MARC_MARCXML, YAZ_MARC_TURBOMARC, and YAZ_MARC_XCHANGE.

int yaz_marc_write_turbomarc ( yaz_marc_t  mt,
WRBUF  wrbuf 
)

writes record in TurboMARC format

Parameters
mthandle
wrbufWRBUF for output
Return values
0OK
-1ERROR

Definition at line 861 of file marcdisp.c.

References yaz_marc_t_::leader_spec, yaz_marc_modify_leader(), and yaz_marc_write_marcxml_ns().

Referenced by yaz_marc_write_mode().

void yaz_marc_write_using_libxml2 ( yaz_marc_t  mt,
int  enable 
)

Enables or disables writing of MARC XML records using Libxml2.

Parameters
mthandle
enable0=disable, 1=enable

Definition at line 1482 of file marcdisp.c.

References yaz_marc_t_::write_using_libxml2.

int yaz_marc_write_xml ( yaz_marc_t  mt,
xmlNode **  root_ptr,
const char *  ns,
const char *  format,
const char *  type 
)

writes MARC record as libxml2 tree

Parameters
mthandle
root_ptrpointer to record node
nsnamespace of record (such as "http://www.loc.gov/MARC21/slim")
formatMarcXchange format (NULL for none)
typeMarcXchange format (NULL for none)
Return values
0Creation successful and *root_ptr is "record" node
-1ERROR

Definition at line 1025 of file marcdisp.c.

References atoi_n_check(), yaz_marc_subfield::code_data, yaz_marc_node::comment, yaz_marc_node::controlfield, yaz_marc_controlfield::data, yaz_marc_node::datafield, get_subfield_len(), yaz_marc_t_::iconv_cd, yaz_marc_node::leader, marc_iconv_reset(), yaz_marc_node::next, yaz_marc_subfield::next, yaz_marc_t_::nodes, yaz_marc_datafield::subfields, yaz_marc_datafield::tag, yaz_marc_controlfield::tag, yaz_marc_node::u, yaz_marc_node::which, wrbuf_alloc(), wrbuf_cstr(), wrbuf_destroy(), wrbuf_iconv_puts(), wrbuf_iconv_write(), wrbuf_rewind(), write_xml_indicator(), YAZ_MARC_COMMENT, YAZ_MARC_CONTROLFIELD, YAZ_MARC_DATAFIELD, and YAZ_MARC_LEADER.

Referenced by yaz_marc_write_marcxml_ns().

static int yaz_marc_write_xml_turbo_xml ( yaz_marc_t  mt,
xmlNode **  root_ptr,
const char *  ns,
const char *  format,
const char *  type 
)
static
void yaz_marc_xml ( yaz_marc_t  mt,
int  xmlmode 
)

set XML mode YAZ_MARC_LINE, YAZ_MARCXML, YAZ_MARC_ISO2709 ..

Parameters
mtMARC handle
xmlmodemode.

This function ONLY affects yaz_marc_write_mode, yaz_marc_write_trailer.

Definition at line 1373 of file marcdisp.c.

References yaz_marc_t_::output_format.

Referenced by convert_marc(), dummy_json_record(), dummy_xml_record(), return_marc_record(), return_opac_record(), and yaz_record_conv_opac_record().

Variable Documentation

const char* controlfield_name[2] = { "controlfield", "c"}
static

Definition at line 647 of file marcdisp.c.

Referenced by yaz_marc_write_marcxml_wrbuf().

const char* datafield_name[2] = { "datafield", "d"}
static

Definition at line 648 of file marcdisp.c.

Referenced by yaz_marc_write_marcxml_wrbuf().

const char* indicator_name[2] = { "ind", "i"}
static

Definition at line 649 of file marcdisp.c.

Referenced by write_xml_indicator(), and yaz_marc_write_marcxml_wrbuf().

const char* leader_name[2] = { "leader", "l"}
static

Definition at line 646 of file marcdisp.c.

Referenced by yaz_marc_write_marcxml_wrbuf().

const char* record_name[2] = { "record", "r"}
static

Definition at line 645 of file marcdisp.c.

Referenced by yaz_marc_write_marcxml_wrbuf().

const char* subfield_name[2] = { "subfield", "s"}
static

Definition at line 650 of file marcdisp.c.

Referenced by add_marc_datafield_turbo_xml(), and yaz_marc_write_marcxml_wrbuf().