source: yaz/trunk/fuentes/doc/marc.html @ 255

Last change on this file since 255 was 255, checked in by mabarracus, 4 years ago

added trusty code to xenial

File size: 9.3 KB
Line 
1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>5. MARC</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="YAZ User's Guide and Reference"><link rel="up" href="tools.html" title="Chapter 7. Supporting Tools"><link rel="prev" href="tools.log.html" title="4. Log"><link rel="next" href="tools.retrieval.html" title="6. Retrieval Facility"></head><body><link rel="stylesheet" type="text/css" href="common/style1.css"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5. MARC</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="tools.log.html">Prev</a> </td><th width="60%" align="center">Chapter 7. Supporting Tools</th><td width="20%" align="right"> <a accesskey="n" href="tools.retrieval.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="marc"></a>5. MARC</h2></div></div></div><p>
2    YAZ provides a fast utility for working with MARC records.
3    Early versions of the MARC utility only allowed decoding of ISO2709.
4    Today the utility may both encode - and decode to a varity of formats.
5   </p><pre class="synopsis">
6    #include &lt;yaz/marcdisp.h&gt;
7
8    /* create handler */
9    yaz_marc_t yaz_marc_create(void);
10    /* destroy */
11    void yaz_marc_destroy(yaz_marc_t mt);
12
13    /* set XML mode YAZ_MARC_LINE, YAZ_MARC_SIMPLEXML, ... */
14    void yaz_marc_xml(yaz_marc_t mt, int xmlmode);
15    #define YAZ_MARC_LINE      0
16    #define YAZ_MARC_SIMPLEXML 1
17    #define YAZ_MARC_OAIMARC   2
18    #define YAZ_MARC_MARCXML   3
19    #define YAZ_MARC_ISO2709   4
20    #define YAZ_MARC_XCHANGE   5
21    #define YAZ_MARC_CHECK     6
22    #define YAZ_MARC_TURBOMARC 7
23    #define YAZ_MARC_JSON      8
24
25    /* supply iconv handle for character set conversion .. */
26    void yaz_marc_iconv(yaz_marc_t mt, yaz_iconv_t cd);
27
28    /* set debug level, 0=none, 1=more, 2=even more, .. */
29    void yaz_marc_debug(yaz_marc_t mt, int level);
30
31    /* decode MARC in buf of size bsize. Returns &gt;0 on success; &lt;=0 on failure.
32    On success, result in *result with size *rsize. */
33    int yaz_marc_decode_buf(yaz_marc_t mt, const char *buf, int bsize,
34                            const char **result, size_t *rsize);
35
36    /* decode MARC in buf of size bsize. Returns &gt;0 on success; &lt;=0 on failure.
37       On success, result in WRBUF */
38    int yaz_marc_decode_wrbuf(yaz_marc_t mt, const char *buf,
39                              int bsize, WRBUF wrbuf);
40
41   </pre><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
42     The synopsis is just a basic subset of all functionality. Refer
43     to the actual header file <code class="filename">marcdisp.h</code> for
44     details.
45    </p></div><p>
46    A MARC conversion handle must be created by using
47    <code class="function">yaz_marc_create</code> and destroyed
48    by calling <code class="function">yaz_marc_destroy</code>.
49   </p><p>
50    All other function operate on a <code class="literal">yaz_marc_t</code> handle.
51    The output is specified by a call to <code class="function">yaz_marc_xml</code>.
52    The <code class="literal">xmlmode</code> must be one of
53    </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">YAZ_MARC_LINE</span></dt><dd><p>
54        A simple line-by-line format suitable for display but not
55        recommend for further (machine) processing.
56       </p></dd><dt><span class="term">YAZ_MARC_MARCXML</span></dt><dd><p>
57        <a class="ulink" href="http://www.loc.gov/standards/marcxml/" target="_top">MARCXML</a>.
58       </p></dd><dt><span class="term">YAZ_MARC_ISO2709</span></dt><dd><p>
59        ISO2709 (sometimes just referred to as "MARC").
60       </p></dd><dt><span class="term">YAZ_MARC_XCHANGE</span></dt><dd><p>
61        <a class="ulink" href="http://www.loc.gov/standards/iso25577/" target="_top">MarcXchange</a>.
62       </p></dd><dt><span class="term">YAZ_MARC_CHECK</span></dt><dd><p>
63        Pseudo format for validation only. Does not generate
64        any real output except diagnostics.
65       </p></dd><dt><span class="term">YAZ_MARC_TURBOMARC</span></dt><dd><p>
66        XML format with same semantics as MARCXML but more compact
67        and geared towards fast processing with XSLT. Refer to
68        <a class="xref" href="marc.html#tools.turbomarc" title="5.1. TurboMARC">Section 5.1, &#8220;TurboMARC&#8221;</a> for more information.
69       </p></dd><dt><span class="term">YAZ_MARC_JSON</span></dt><dd><p>
70        <a class="ulink" href="http://dilettantes.code4lib.org/blog/2010/09/a-proposal-to-serialize-marc-in-json/" target="_top">MARC-in_JSON</a> format.
71       </p></dd></dl></div><p>
72   </p><p>
73    The actual conversion functions are
74    <code class="function">yaz_marc_decode_buf</code> and
75    <code class="function">yaz_marc_decode_wrbuf</code> which decodes and encodes
76    a MARC record. The former function operates on simple buffers, the
77    stores the resulting record in a WRBUF handle (WRBUF is a simple string
78    type).
79   </p><div class="example"><a name="example.marc.display"></a><p class="title"><b>Example 7.18. Display of MARC record</b></p><div class="example-contents"><p>
80     The following program snippet illustrates how the MARC API may
81     be used to convert a MARC record to the line-by-line format:
82     </p><pre class="programlisting">
83      void print_marc(const char *marc_buf, int marc_buf_size)
84      {
85         char *result;      /* for result buf */
86         size_t result_len;    /* for size of result */
87         yaz_marc_t mt = yaz_marc_create();
88         yaz_marc_xml(mt, YAZ_MARC_LINE);
89         yaz_marc_decode_buf(mt, marc_buf, marc_buf_size,
90                             &amp;result, &amp;result_len);
91         fwrite(result, result_len, 1, stdout);
92         yaz_marc_destroy(mt);  /* note that result is now freed... */
93      }
94
95     </pre><p>
96    </p></div></div><br class="example-break"><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="tools.turbomarc"></a>5.1. TurboMARC</h3></div></div></div><p>
97     TurboMARC is yet another XML encoding of a MARC record. The format
98     was designed for fast processing with XSLT.
99    </p><p>
100     Applications like
101     Pazpar2 uses XSLT to convert an XML encoded MARC record to an internal
102     representation. This conversion mostly check the tag of a MARC field
103     to determine the basic rules in the conversion. This check is
104     costly when that is tag is encoded as an attribute in MARCXML.
105     By having the tag value as the element instead, makes processing
106     many times faster (at least for Libxslt).
107    </p><p>
108     TurboMARC is encoded as follows:
109     </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
110        Record elements is part of namespace
111        "<code class="literal">http://www.indexdata.com/turbomarc</code>".
112      </p></li><li class="listitem"><p>
113        A record is enclosed in element <code class="literal">r</code>.
114      </p></li><li class="listitem"><p>
115        A collection of records is enclosed in element
116        <code class="literal">collection</code>.
117       </p></li><li class="listitem"><p>
118        The leader is encoded as element <code class="literal">l</code> with the
119        leader content as its (text) value.
120      </p></li><li class="listitem"><p>
121        A control field is encoded as element <code class="literal">c</code> concatenated
122        with the tag value of the control field if the tag value
123        matches the regular expression <code class="literal">[a-zA-Z0-9]*</code>.
124        If the tag value do not match the regular expression
125        <code class="literal">[a-zA-Z0-9]*</code> the control field is encoded
126        as element <code class="literal">c</code> and attribute <code class="literal">code</code>
127        will hold the tag value.
128        This rule ensure that in the rare cases where a tag value might
129        result in a non-wellformed XML YAZ encode it as a coded attribute
130        (as in MARCXML).
131       </p><p>
132        The control field content is the the text value of this element.
133        Indicators are encoded as attribute names
134        <code class="literal">i1</code>, <code class="literal">i2</code>, etc.. and
135        corresponding values for each indicator.
136       </p></li><li class="listitem"><p>
137        A data field is encoded as element <code class="literal">d</code> concatenated
138        with the tag value of the data field or using the attribute
139        <code class="literal">code</code> as described in the rules for control fields.
140        The children of the data field element is subfield elements.
141        Each subfield element is encoded as <code class="literal">s</code>
142        concatenated with the sub field code.
143        The text of the subfield element is the contents of the subfield.
144        Indicators are encoded as attributes for the data field element similar
145        to the encoding for control fields.
146      </p></li></ul></div><p>
147    </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="tools.log.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="tools.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="tools.retrieval.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">4. Log </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 6. Retrieval Facility</td></tr></table></div></body></html>
Note: See TracBrowser for help on using the repository browser.