Examples
Unit tests
Tested with acc by running
acc instance exec -f test/integration/getValue.spec.js in a sandbox:
loadLibrary("/nl/core/shared/nl.js"); // import NL.assert
const doc = DOMDocument.fromJXON({ root: { item: { id: 7 } } }); // <root><item id="7"/></root>
const root = doc.root;
const label = doc.createElement("label");
label.appendChild(doc.createTextNode("Hello"));
root.appendChild(label);
context.test0 = NL.assert(root.toXMLString() === '<root><item id="7"/><label>Hello</label></root>');
context.test1 = NL.assert(root.getValue("item/@id") === "7");
context.test2 = NL.assert(root.getValue("label") === "Hello");
context.test3 = NL.assert(typeof root.getValue("item/@id") === "string");
context.test4 = NL.assert(root.getNumberValue("item/@id") === 7);
context.test5 = NL.assert(typeof root.getNumberValue("item/@id") === "number");
context.test7 = NL.assert(root.getValue("doesNotExist") === "");
context.test8 = NL.assert(root.getValue("@@bad") === "");
try {
context.test9err = root.getValue("item[");
} catch (e) {
context.test9 = NL.assert(e.toString() === "16384"); // 2^14
}See also
-
📕 DOMElement- Adobe Campaign's XML element: the type returned by queryDef and SOAP calls. Can be read and traversed. -
📕 NL.is- Adobe Campaign's type helpers to check XML values.