Created
May 3, 2021 09:49
-
-
Save jweisman/3699b73593982e427530403dd33995f9 to your computer and use it in GitHub Desktop.
Alma BIB API - Working with XML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var alma = require ('almarestapi-lib'); | |
var xpath = require('xpath'); | |
var dom = require('xmldom').DOMParser | |
const XPATH_TITLE = '/record/datafield[@tag="245"]/subfield[@code="a"]'; | |
const XPATH_AUTHOR = '/record/datafield[@tag="100"]/subfield[@code="a"]'; | |
const MMS_ID = '99469654400561'; | |
let title, author, bib, doc; | |
( async () => { | |
/* With application/xml */ | |
bib = (await alma.getXmlp(`/bibs/${MMS_ID}`)) | |
doc = new dom().parseFromString(bib) | |
title = xpath.select('/bib/' + XPATH_TITLE, doc)[0].firstChild.data; | |
console.log('title', title); | |
/* With application/json */ | |
bib = (await alma.getp(`/bibs/${MMS_ID}`)).anies[0]; | |
doc = new dom().parseFromString(bib) | |
author = xpath.select(XPATH_AUTHOR, doc)[0].firstChild.data; | |
console.log('author', author); | |
})() |
Author
jweisman
commented
May 3, 2021
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment