@softchef/cdk-iot-device-management
Version:
IoT device management is composed of things, thing types, thing groups, jobs, files API services. The constructs can be used independently, that are based on full-managed service to create an API Gateway & Lambda function.
41 lines (40 loc) • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.XmlNode = void 0;
const escape_attribute_1 = require("./escape-attribute");
class XmlNode {
constructor(name, children = []) {
this.name = name;
this.children = children;
this.attributes = {};
}
withName(name) {
this.name = name;
return this;
}
addAttribute(name, value) {
this.attributes[name] = value;
return this;
}
addChildNode(child) {
this.children.push(child);
return this;
}
removeAttribute(name) {
delete this.attributes[name];
return this;
}
toString() {
const hasChildren = Boolean(this.children.length);
let xmlText = `<${this.name}`;
const attributes = this.attributes;
for (const attributeName of Object.keys(attributes)) {
const attribute = attributes[attributeName];
if (typeof attribute !== "undefined" && attribute !== null) {
xmlText += ` ${attributeName}="${escape_attribute_1.escapeAttribute("" + attribute)}"`;
}
}
return (xmlText += !hasChildren ? "/>" : `>${this.children.map((c) => c.toString()).join("")}</${this.name}>`);
}
}
exports.XmlNode = XmlNode;