UNPKG

typesxml

Version:

Open source XML library written in TypeScript

58 lines 1.97 kB
/******************************************************************************* * 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 { XMLUtils } from '../XMLUtils.js'; import { DTDElementNameParticle } from './DTDElementNameParticle.js'; export class DTDSequenceModel { cardinality = ''; children = []; constructor(children) { if (children) this.children = children; } getType() { return 'sequence'; } addChild(child) { this.children.push(child); } getChildren() { return this.children; } validate() { // Cardinality must be '', '*', '+', or '?' if (this.cardinality && !['*', '+', '?'].includes(this.cardinality)) { return false; } // At least one child required for valid model if (this.children.length === 0) { return false; } // Validate each child and its name if it's an element particle for (const child of this.children) { if (!child.validate()) { return false; } // Only check name if child is DTDElementNameParticle if (child instanceof DTDElementNameParticle) { if (!XMLUtils.isValidXMLName(child.getName())) { return false; } } } return true; } toBNF() { let bnf = this.children.map(child => child.toBNF()).join(', '); return bnf + (this.cardinality ? this.cardinality : ''); } } //# sourceMappingURL=DTDSequenceModel.js.map