Skip to content

Instantly share code, notes, and snippets.

@jmakeig
Last active December 14, 2018 18:29
Show Gist options
  • Save jmakeig/9a6aad1ebbe393128d5a643914619a32 to your computer and use it in GitHub Desktop.
Save jmakeig/9a6aad1ebbe393128d5a643914619a32 to your computer and use it in GitHub Desktop.
Tagged template literal to build XML Nodes in MarkLogic.
'use strict';
function xml(strings, ...values) {
let str = '';
for (let i = 0; i < strings.length; i++) {
str += strings[i] + (values[i] || '');
}
return fn.head(
xdmp.unquote(str, null, 'format-xml') // Sequence
); // Document
}
// Usage:
const name = 'Foo Bar';
const color = 'orange';
const doc = xml`
<product xmlns="products">
<name>${name}</name>
<color>${color}</color>
</product>
`;
console.assert(doc instanceof Document);
doc;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment