Skip to content

Instantly share code, notes, and snippets.

@atbradley
Created May 16, 2012 13:41
Show Gist options
  • Save atbradley/2710414 to your computer and use it in GitHub Desktop.
Save atbradley/2710414 to your computer and use it in GitHub Desktop.
EAP creation example using XmlSlurper
import groovy.xml.MarkupBuilder
//Read a tab-delimited file.
def tdl = new TLD('comiclist.txt', false, 'Box No.')
/*
//Turn it into a simple xml format, one 'comic' per spreadsheet row.
def wrt = new StringWriter()
def xml = new MarkupBuilder(wrt)
xml.comics {
tdl.data.each { cbook ->
comic {
cbook.each {
//println "${it.key}: ${it.value}"
def fieldName = it.key.toLowerCase().replaceAll(/[^\w\s]/, '').replaceAll(/\s+/, '-')
"$fieldName" it.value
}
}
}
}
new File("zollinger.xml").text = wrt.toString()
*/
def wrt = new StringWriter()
wrt << """<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE ead SYSTEM "ead.dtd">
"""
ead = new MarkupBuilder(wrt)
ead.ead( audience: "external", xmlns: "urn:isbn:1-931666-22-9" ) {
eadheader {
eadid (countrycode: "us", mainagencycode: "rpb", identifier: "zollinger-comics", "zollinger-comics")
filedesc {
titlestmt {
titleproper "Guide to the Zollinger Comic Book Collection"
//subtitle "" //optional
//author {} //optional
//sponsor {} //optional
}
//editionstmt {} //optional
//publicationstmt {} //optional
//seriesstmt {} //optional
//notestmt {} //optional
}
profiledesc {
creation "Machine-readable finding aid derived from MS Excel."
langusage {
mkp.yield "Description is in"
language "English"
}
} //optional
//revisiondesc {} //optional
}
//frontmatter {} //optional
archdesc(level: "collection") {
did {
head "Zollinger Comic Book Collection"
unitid( countrycode: 'us', repositorycode: "rpb", identifier: 'zollinger-comics', 'zollinger-comics')
}
dsc(type: "combined") {
head "Contents"
//findAll{ it.key.trim()=='Box 1' }.
tdl.data.each { box ->
c (level: "recordgrp") {
did {
container (type: "box-folder", box.key)
}
box.value.each { comic ->
c (level: "file") {
did {
unittitle {
if ( comic.'Issue Title' ) {
mkp.yield comic.'Issue Title'
}
bibseries {
mkp.yield comic.Series
if ( comic.Volume && comic.Issue ) {
num "${comic.Volume} ${comic.Issue}"
} else if ( comic.Volume || comic.Issue ) {
num comic.Volume + comic.Issue
}
}
}
[ 'Artist', 'Colorist', 'Cover Artist', 'Cover Colorist',
'Cover Inker', 'Cover Painter', 'Cover Penciller',
'Inker', 'Letterer', 'Penciller', 'Writer'].each {
if ( comic[it] ) {
comic[it].split(';').each() { name ->
origination(label: "$it: ") {
persname(role: "creator") {
mkp.yield name.trim()
}
}
}
}
}
if ( comic.Plot ) {
'abstract' comic.Plot
}
note {
p "Genre: ${comic.Genre}"
}
if ( comic.Character ) {
note {
list {
head "Characters:"
comic.Character.split(';')*.trim().each() {
item it
}
}
}
}
note { //publicationstmt {
try {
pubdt = Date.parse( 'MMM-yy', "${comic.'Publication Date'}")
} catch (e) {}
p {
mkp.yield "Published by ${comic.Publisher}, "
if ( pubdt ) {
date( normal: pubdt.format( 'yyyy-MM' ), pubdt.format( 'MMMM yyyy' ) )
} else { date comic.'Publication Year' }
mkp.yield "."
}
//publisher { comic.Publisher }
//address {}
p {
mkp.yield "Cover price: "
num { comic.'Cover Price' }
}
}
}
}
}
}
}
}
}
}
//print wrt.toString()
new File("zollinger.ead.xml").setText(wrt.toString(), 'UTF-8')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment