Skip to content

Instantly share code, notes, and snippets.

@jweisman
Created May 3, 2021 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jweisman/3699b73593982e427530403dd33995f9 to your computer and use it in GitHub Desktop.
Save jweisman/3699b73593982e427530403dd33995f9 to your computer and use it in GitHub Desktop.
Alma BIB API - Working with XML
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);
})()
@jweisman
Copy link
Author

jweisman commented May 3, 2021

$ npm i xmldom xpath almarestapi-lib
$ node index.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment