UNPKG

typesxml

Version:

Open source XML library written in TypeScript

95 lines 2.96 kB
"use strict"; /******************************************************************************* * Copyright (c) 2023-2026 Maxprograms. * * This program and the accompanying materials * are made available under the terms of the Eclipse License 1.0 * which accompanies this distribution, and is available at * https://www.eclipse.org/org/documents/epl-v10.html * * Contributors: * Maxprograms - initial API and implementation *******************************************************************************/ Object.defineProperty(exports, "__esModule", { value: true }); exports.XMLDocument = void 0; const Constants_js_1 = require("./Constants.js"); const XMLDeclaration_js_1 = require("./XMLDeclaration.js"); const XMLElement_js_1 = require("./XMLElement.js"); const XMLUtils_js_1 = require("./XMLUtils.js"); class XMLDocument { content; documentType; constructor() { this.content = new Array(); } contentIterator() { return this.content.values(); } setRoot(root) { this.content.push(root); } getRoot() { for (let node of this.content) { if (node instanceof XMLElement_js_1.XMLElement) { return node; } } return undefined; } setDocumentType(documentType) { this.documentType = documentType; this.content.push(documentType); } getDocumentType() { return this.documentType; } setXmlDeclaration(declaration) { this.content.unshift(declaration); } getXmlDeclaration() { if (this.content[0] instanceof XMLDeclaration_js_1.XMLDeclaration) { return this.content[0]; } return undefined; } addComment(comment) { this.content.push(comment); } addProcessingInstruction(pi) { this.content.push(pi); } addTextNode(node) { this.content.push(node); } getNodeType() { return Constants_js_1.Constants.DOCUMENT_NODE; } toString() { let result = ''; let isXml10 = true; let xmlDeclaration = this.getXmlDeclaration(); if (xmlDeclaration) { isXml10 = xmlDeclaration.getVersion() === '1.0'; } this.content.forEach((node) => { result += isXml10 ? XMLUtils_js_1.XMLUtils.validXml10Chars(node.toString()) : XMLUtils_js_1.XMLUtils.validXml11Chars(node.toString()); }); return result; } equals(node) { if (node instanceof XMLDocument) { if (this.content.length !== node.content.length) { return false; } for (let i = 0; i < this.content.length; i++) { if (!this.content[i].equals(node.content[i])) { return false; } } return true; } return false; } } exports.XMLDocument = XMLDocument; //# sourceMappingURL=XMLDocument.js.map