1MARC::File::XML(3)    User Contributed Perl Documentation   MARC::File::XML(3)
2
3
4

NAME

6       MARC::File::XML - Work with MARC data encoded as XML
7

SYNOPSIS

9           ## Loading with USE options
10           use MARC::File::XML ( BinaryEncoding => 'utf8', RecordFormat => 'UNIMARC' );
11
12           ## Setting the record format without USE options
13           MARC::File::XML->default_record_format('USMARC');
14
15           ## reading with MARC::Batch
16           my $batch = MARC::Batch->new( 'XML', $filename );
17           my $record = $batch->next();
18
19           ## or reading with MARC::File::XML explicitly
20           my $file = MARC::File::XML->in( $filename );
21           my $record = $file->next();
22
23           ## serialize a single MARC::Record object as XML
24           print $record->as_xml();
25
26           ## write a bunch of records to a file
27           my $file = MARC::File::XML->out( 'myfile.xml' );
28           $file->write( $record1 );
29           $file->write( $record2 );
30           $file->write( $record3 );
31           $file->close();
32
33           ## instead of writing to disk, get the xml directly
34           my $xml = join( "\n",
35               MARC::File::XML::header(),
36               MARC::File::XML::record( $record1 ),
37               MARC::File::XML::record( $record2 ),
38               MARC::File::XML::footer()
39           );
40

DESCRIPTION

42       The MARC-XML distribution is an extension to the MARC-Record
43       distribution for working with MARC21 data that is encoded as XML. The
44       XML encoding used is the MARC21slim schema supplied by the Library of
45       Congress. More information may be obtained here:
46       http://www.loc.gov/standards/marcxml/
47
48       You must have MARC::Record installed to use MARC::File::XML. In fact
49       once you install the MARC-XML distribution you will most likely not use
50       it directly, but will have an additional file format available to you
51       when you use MARC::Batch.
52
53       This version of MARC-XML supersedes an the versions ending with 0.25
54       which were used with the MARC.pm framework. MARC-XML now uses
55       MARC::Record exclusively.
56
57       If you have any questions or would like to contribute to this module
58       please sign on to the perl4lib list. More information about perl4lib is
59       available at <http://perl4lib.perl.org>.
60

METHODS

62       When you use MARC::File::XML your MARC::Record objects will have two
63       new additional methods available to them:
64
65   MARC::File::XML->default_record_format([$format])
66       Sets or returns the default record format used by MARC::File::XML.
67       Valid formats are MARC21, USMARC, UNIMARC and UNIMARCAUTH.
68
69           MARC::File::XML->default_record_format('UNIMARC');
70
71   as_xml()
72       Returns a MARC::Record object serialized in XML. You can pass an
73       optional format parameter to tell MARC::File::XML what type of record
74       (USMARC, UNIMARC, UNIMARCAUTH) you are serializing.
75
76           print $record->as_xml([$format]);
77
78   as_xml_record([$format])
79       Returns a MARC::Record object serialized in XML without a collection
80       wrapper.  You can pass an optional format parameter to tell
81       MARC::File::XML what type of record (USMARC, UNIMARC, UNIMARCAUTH) you
82       are serializing.
83
84           print $record->as_xml_record('UNIMARC');
85
86   new_from_xml([$encoding, $format])
87       If you have a chunk of XML and you want a record object for it you can
88       use this method to generate a MARC::Record object.  You can pass an
89       optional encoding parameter to specify which encoding (UTF-8 or MARC-8)
90       you would like the resulting record to be in.  You can also pass a
91       format parameter to specify the source record type, such as UNIMARC,
92       UNIMARCAUTH, USMARC or MARC21.
93
94           my $record = MARC::Record->new_from_xml( $xml, $encoding, $format );
95
96       Note: only works for single record XML chunks.
97
98       If you want to write records as XML to a file you can use out() with
99       write() to serialize more than one record as XML.
100
101   out()
102       A constructor for creating a MARC::File::XML object that can write XML
103       to a file. You must pass in the name of a file to write XML to.  If the
104       $encoding parameter or the DefaultEncoding (see above) is set to UTF-8
105       then the binmode of the output file will be set appropriately.
106
107           my $file = MARC::File::XML->out( $filename [, $encoding] );
108
109   write()
110       Used in tandem with out() to write records to a file.
111
112           my $file = MARC::File::XML->out( $filename );
113           $file->write( $record1 );
114           $file->write( $record2 );
115
116   close()
117       When writing records to disk the filehandle is automatically closed
118       when you the MARC::File::XML object goes out of scope. If you want to
119       close it explicitly use the close() method.
120
121       If you want to generate batches of records as XML, but don't want to
122       write to disk you'll have to use header(), record() and footer() to
123       generate the different portions.
124
125           $xml = join( "\n",
126               MARC::File::XML::header(),
127               MARC::File::XML::record( $record1 ),
128               MARC::File::XML::record( $record2 ),
129               MARC::File::XML::record( $record3 ),
130               MARC::File::XML::footer()
131           );
132
133   header()
134       Returns a string of XML to use as the header to your XML file.
135
136   footer()
137       Returns a string of XML to use at the end of your XML file.
138
139   record()
140       Returns a chunk of XML suitable for placement between the header and
141       the footer.
142
143   decode()
144       You probably don't ever want to call this method directly. If you do
145       you should pass in a chunk of XML as the argument.
146
147       It is normally invoked by a call to next(), see MARC::Batch or
148       MARC::File.
149
150   MARC::File::XML->set_parser($parser)
151       Pass a XML::LibXML parser to MARC::File::XML for it to use.  This is
152       optional, meant for use by applications that maintain a shared parser
153       object or which require that external entities be processed.  Note that
154       the latter is a potential security risk; see
155       <https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Processing>.
156
157   encode()
158       You probably want to use the as_xml() method on your MARC::Record
159       object instead of calling this directly. But if you want to you just
160       need to pass in the MARC::Record object you wish to encode as XML, and
161       you will be returned the XML as a scalar.
162

TODO

164       •   Support for callback filters in decode().
165

SEE ALSO

167       <http://www.loc.gov/standards/marcxml/>
168       MARC::File::USMARC
169       MARC::Batch
170       MARC::Record
171

AUTHORS

173       •   Ed Summers <ehs@pobox.com>
174
175
176
177perl v5.34.0                      2022-01-21                MARC::File::XML(3)
Impressum