X hits on this document





66 / 142


MARC records is extraordinarily valuable, but the way the encoding scheme, while academically inter- esting, is archane.

Exercise - Convert MARC to MARCXML

In this exercise you will convert a MARC data file into a single MARCXML file.

  • 1.

    Install MARC::File::XML. Using Windows you can use ppm and then install MARC::File::XML. Using Unix you can sudo cpan and then install MARC::File::XML at the cpan prompt.

  • 2.

    After installation a file named marc2xml will be installed in your path, but it is provided in the bin directory for ease-of-use. Open bin/marc2xml.pl in your editor and notice how short the code is.

  • 3.

    Open a command prompt and change directories to the workbook's root.

  • 4.

    Enter this command: perl bin/marc2xml.pl marc/single/catalog.marc | more . Notice how the

output is a stream of MARCXML data.


Enter the command again, but this time pipe the output to a file: perl bin/marc2xml.pl marc/ single/catalog.marc > xml-data/marcxml/single/catalog.xml . Open xml- data/marcxml/single/catalog.xml in your Web browser or editor to verify that the process worked. As an extra exercise, use xmllint to validate the output.

Exercise - Validating schema

In this exercise you will validate MARCXML data against a schema.

  • 1.

    Open dtds/marcxml/MARC21slim.xsd in your text editor or Web browser. This file is schema. Its purpose is to define the shape and structure of XML documents in the same way DTDs define shape and structure. Schema files are XML files which make them easier to work with than DTDs. They also provide the means for more granular element and attribute definitions. For example, an data can be specified to be in a YYYY-MM-DD format. DTDs do not offer this sort of flexibility. MARC21slim.xsd is used to define the shape of MARCXML files.

  • 2.

    Open a comand prompt and change to the root of the workshop's directory.


Validate the file you created in the previous exercise with this command: xmllint --noout --schema dtds/marcxml/MARC21slim.xsd xml-data/marcxml/single/catalog.xml . The result should be "xml-data/marcxml/single/catalog.xml validates".

Based on the author's experience, xmllint's support of schema is not nearly as strong as its support for DTDs. Using xmllint to validate other XML files using schema produces unusual results. Your mileage will vary.


Document info
Document views224
Page views230
Page last viewedThu Oct 20 20:11:03 UTC 2016