UNPKG

libxmljs

Version:

libxml bindings for v8 javascript engine

70 lines 4.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var libxml = require("../index"); var index_1 = require("../index"); var body = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<root><node attr-one-key='attr-one-value' attr-two-key='attr-two-value' attr-three-key='attr-three-value' /></root>"; module.exports.new = function (assert) { var _a; var doc = libxml.parseXml(body); var node = doc.get("node"); node === null || node === void 0 ? void 0 : node.setAttribute("new-attr-key", "new-attr-value"); assert.equal("new-attr-value", (_a = node.getAttribute("new-attr-key")) === null || _a === void 0 ? void 0 : _a.value()); assert.done(); }; module.exports.create_with_namespace = function (assert) { var _a, _b, _c; var doc = libxml.parseXml("<?xml version='1.0' encoding='UTF-8'?>\n" + "<root><node attr-one-key='attr-one-value' attr-two-key='attr-two-value' attr-three-key='attr-three-value' /></root>"); var node = doc.get("node"); assert.equal(node instanceof index_1.XMLElement, true); var attr = node.setAttribute("new-attr-key", "new-attr-value"); var ns = node === null || node === void 0 ? void 0 : node.namespace("ns-prefix", "ns-url"); assert.ok(attr); assert.ok(ns === null || ns === void 0 ? void 0 : ns.prefix()); assert.ok((_a = node === null || node === void 0 ? void 0 : node.namespace()) === null || _a === void 0 ? void 0 : _a.prefix()); assert.equal(ns === null || ns === void 0 ? void 0 : ns.prefix(), (_b = node === null || node === void 0 ? void 0 : node.namespace()) === null || _b === void 0 ? void 0 : _b.prefix()); assert.equal(ns === null || ns === void 0 ? void 0 : ns.href(), (_c = node === null || node === void 0 ? void 0 : node.namespace()) === null || _c === void 0 ? void 0 : _c.href()); assert.done(); }; module.exports.getters = function (assert) { var _a, _b, _c, _d, _e, _f; var doc = libxml.parseXml(body); var node = doc.get("node"); assert.equal("attr-one-key", (_a = node.getAttribute("attr-one-key")) === null || _a === void 0 ? void 0 : _a.name()); assert.equal("attr-one-value", (_b = node.getAttribute("attr-one-key")) === null || _b === void 0 ? void 0 : _b.value()); assert.equal("node", (_c = node.getAttribute("attr-one-key")) === null || _c === void 0 ? void 0 : _c.node().name()); assert.ok("attribute", (_d = node.getAttribute("attr-two-key")) === null || _d === void 0 ? void 0 : _d.type()); assert.equal("attr-one-key", (_e = node.getAttribute("attr-two-key")) === null || _e === void 0 ? void 0 : _e.prevSibling().name()); assert.equal("attr-three-key", (_f = node.getAttribute("attr-two-key")) === null || _f === void 0 ? void 0 : _f.nextSibling().name()); assert.done(); }; module.exports.setters = function (assert) { var _a, _b; var doc = libxml.parseXml(body); var node = doc.get("node"); (_a = node.getAttribute("attr-one-key")) === null || _a === void 0 ? void 0 : _a.value("new-value"); assert.equal((_b = node.getAttribute("attr-one-key")) === null || _b === void 0 ? void 0 : _b.value(), "new-value"); assert.done(); }; module.exports.namespace = function (assert) { var _a, _b; var doc = libxml.parseXml(body); var node = doc.get("node"); var ns = libxml.Namespace(node, "ns-prefix", "ns-uri"); var attr = node.getAttribute("attr-one-key"); attr === null || attr === void 0 ? void 0 : attr.namespace(ns); assert.equal(ns.prefix(), (_a = attr === null || attr === void 0 ? void 0 : attr.namespace()) === null || _a === void 0 ? void 0 : _a.prefix()); assert.equal(ns.href(), (_b = attr === null || attr === void 0 ? void 0 : attr.namespace()) === null || _b === void 0 ? void 0 : _b.href()); assert.done(); }; module.exports.remove = function (assert) { var doc = libxml.parseXml(body); var node = doc.get("node"); var attr = node.getAttribute("attr-one-key"); assert.ok(node.getAttribute("attr-one-key")); attr === null || attr === void 0 ? void 0 : attr.remove(); assert.ok(!node.getAttribute("attr-one-key")); assert.done(); }; //# sourceMappingURL=attribute.js.map