typesxml
Version:
Open source XML library written in TypeScript
60 lines • 2.12 kB
JavaScript
;
/*******************************************************************************
* Copyright (c) 2023-2026 Maxprograms.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public 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.ElementDecl = void 0;
const Constants_js_1 = require("../Constants.js");
const DTDContentModelParser_js_1 = require("./DTDContentModelParser.js");
class ElementDecl {
name;
contentSpec;
constructor(name, contentSpec) {
this.name = name;
this.contentSpec = contentSpec;
this.validateContentSpec();
}
validateContentSpec() {
const validSpecs = ['EMPTY', 'ANY'];
if (validSpecs.includes(this.contentSpec)) {
return;
}
// Build and validate the content model using the complete parser
let simplified = this.contentSpec.replaceAll(/\r?\n/g, ' ');
simplified = simplified.replaceAll(/\s+/g, '').trim();
const parser = new DTDContentModelParser_js_1.DTDContentModelParser(simplified);
const model = parser.parse();
if (!model.validate()) {
throw new Error('Invalid content specification: ' + simplified);
}
}
getName() {
return this.name;
}
getContentSpec() {
return this.contentSpec;
}
getNodeType() {
return Constants_js_1.Constants.ELEMENT_DECL_NODE;
}
toString() {
return '<!ELEMENT ' + this.name + ' ' + this.contentSpec + '>';
}
equals(node) {
if (node instanceof ElementDecl) {
return this.name === node.name &&
this.contentSpec === node.contentSpec;
}
return false;
}
}
exports.ElementDecl = ElementDecl;
//# sourceMappingURL=ElementDecl.js.map