| Marc Kupietz | 9367d7e | 2024-09-29 12:54:39 +0200 | [diff] [blame] | 1 | #!/bin/env Rscript |
| 2 | library(glue) |
| 3 | library(tidyverse) |
| 4 | library(readr) |
| 5 | |
| 6 | df <- read_delim("Metadaten.csv", delim = ";", locale = readr::locale(encoding = "cp1252")) |
| 7 | |
| 8 | recordBuilder <- function(ID, ISBN, author, creationDate, title, publisher, pubPlace, ...) { |
| 9 | glue::glue( |
| 10 | ' <record> |
| 11 | <recordSchema>oai_dc</recordSchema> |
| 12 | <recordPacking>xml</recordPacking> |
| 13 | <recordData> |
| 14 | <dc xmlns:dnb="http://d-nb.de/standards/dnbterms" xmlns:tel="http://krait.kb.nl/coop/tel/handbook/telterms.html" xmlns="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
| 15 | <dc:title>{title}</dc:title> |
| 16 | <dc:creator>{author}</dc:creator> |
| 17 | <dc:publisher>{publisher}</dc:publisher> |
| 18 | <dc:date>{creationDate}</dc:date> |
| 19 | <dc:language>ger</dc:language> |
| 20 | <dc:identifier xsi:type="tel:ISBN">{ISBN}</dc:identifier> |
| 21 | <dc:identifier xsi:type="dnb:IDN">{ID}</dc:identifier> |
| 22 | <dc:subject>830 Deutsche Literatur</dc:subject> |
| 23 | <dc:subject>B Belletristik</dc:subject> |
| 24 | <dc:type>Online-Ressource</dc:type> |
| 25 | </dc> |
| 26 | </recordData> |
| 27 | </record> |
| 28 | ') |
| 29 | } |
| 30 | |
| 31 | escape_xml <- function(x) { |
| 32 | x <- gsub("&", "&", x) |
| 33 | x <- gsub("<", "<", x) |
| 34 | x <- gsub(">", ">", x) |
| 35 | x <- gsub("\"", """, x) |
| 36 | x <- gsub("'", "'", x) |
| 37 | return(x) |
| 38 | } |
| 39 | |
| 40 | df <- df %>% |
| 41 | mutate(across(everything(), ~ escape_xml(.))) |
| 42 | |
| 43 | xmlRecords <- df %>% purrr::pmap(recordBuilder) %>% unlist %>% paste(collapse = "\n") |
| 44 | |
| 45 | glue::glue( |
| 46 | '<?xml version="1.0" encoding="UTF-8"?> |
| 47 | <searchRetrieveResponse xmlns="http://www.loc.gov/zing/srw/"> |
| 48 | <records> |
| 49 | {xmlRecords} |
| 50 | <!-- From here on only fake examples for testing --> |
| 51 | <record> |
| 52 | <recordSchema>oai_dc</recordSchema> |
| 53 | <recordPacking>xml</recordPacking> |
| 54 | <recordData> |
| 55 | <dc xmlns:dnb="http://d-nb.de/standards/dnbterms" xmlns:tel="http://krait.kb.nl/coop/tel/handbook/telterms.html" xmlns="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
| 56 | <dc:title>Ein Hauch von Meer und Mord : Juist-Krimi / Barbara Saladin</dc:title> |
| 57 | <dc:creator>Saladin, Barbara [Verfasser]</dc:creator> |
| 58 | <dc:publisher>Hillesheim : KBV Verlags- & Medien</dc:publisher> |
| 59 | <dc:date>2012</dc:date> |
| 60 | <dc:language>ger</dc:language> |
| 61 | <dc:identifier xsi:type="tel:URN">urn:nbn:de:101:1-2012112917525</dc:identifier> |
| 62 | <dc:identifier xsi:type="tel:URL">http://nbn-resolving.de/urn:nbn:de:101:1-2012112917525</dc:identifier> |
| 63 | <dc:identifier xsi:type="tel:ISBN">978-3-95441-123-8</dc:identifier> |
| 64 | <dc:identifier xsi:type="tel:URL">http://d-nb.info/1028379862/34</dc:identifier> |
| 65 | <dc:identifier xsi:type="dnb:IDN">8999999998</dc:identifier> |
| 66 | <dc:subject>830 Deutsche Literatur</dc:subject> |
| 67 | <dc:subject>B Belletristik</dc:subject> |
| 68 | <dc:type>Online-Ressource</dc:type> |
| 69 | </dc> |
| 70 | </recordData> |
| 71 | <recordPosition>1</recordPosition> |
| 72 | </record> |
| 73 | |
| 74 | <record> |
| 75 | <recordSchema>oai_dc</recordSchema> |
| 76 | <recordPacking>xml</recordPacking> |
| 77 | <recordData> |
| 78 | <dc xmlns:dnb="http://d-nb.de/standards/dnbterms" xmlns:tel="http://krait.kb.nl/coop/tel/handbook/telterms.html" xmlns="http://www.openarchives.org/OAI/2.0/oai_dc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> |
| 79 | <dc:title>Herzblut : Kriminalroman aus Düsseldorf / David Daniel</dc:title> |
| 80 | <dc:creator>Daniel, David [Verfasser]</dc:creator> |
| 81 | <dc:publisher>Hillesheim : KBV Verlags- & Medien</dc:publisher> |
| 82 | <dc:date>2018</dc:date> |
| 83 | <dc:language>ger</dc:language> |
| 84 | <dc:identifier xsi:type="tel:URN">urn:nbn:de:101:1-2012112917539</dc:identifier> |
| 85 | <dc:identifier xsi:type="tel:URL">http://nbn-resolving.de/urn:nbn:de:101:1-2012112917539</dc:identifier> |
| 86 | <dc:identifier xsi:type="tel:ISBN">978-3-95441-027-9</dc:identifier> |
| 87 | <dc:identifier xsi:type="tel:URL">http://d-nb.info/1028379870/34</dc:identifier> |
| 88 | <dc:identifier xsi:type="dnb:IDN">8999999999</dc:identifier> |
| 89 | <dc:subject>830 Deutsche Literatur</dc:subject> |
| 90 | <dc:subject>B Belletristik</dc:subject> |
| 91 | <dc:type>Online-Ressource</dc:type> |
| 92 | </dc> |
| 93 | </recordData> |
| 94 | </record> |
| 95 | </records> |
| 96 | </searchRetrieveResponse> |
| 97 | ' |
| 98 | ) %>% cat(file = "static_metadata.xml") |
| 99 | |