typesxml
Version:
Open source XML library written in TypeScript
56 lines • 1.93 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
*******************************************************************************/
import { Constants } from "../Constants.js";
import { DTDContentModelParser } from "./DTDContentModelParser.js";
export 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(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.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;
}
}
//# sourceMappingURL=ElementDecl.js.map