typesxml
Version:
Open source XML library written in TypeScript
48 lines • 2.02 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 { SchemaParticle } from './SchemaParticle.js';
export class SchemaElementParticle extends SchemaParticle {
name;
additionalNames;
constructor(name, minOccurs = 1, maxOccurs = 1, additionalNames) {
super(minOccurs, maxOccurs);
this.name = name;
this.additionalNames = additionalNames !== undefined ? additionalNames : new Set();
}
matchOnce(children, pos, _nsMap, _childNamespaces) {
if (pos >= children.length) {
return [];
}
const childName = children[pos];
if (childName === this.name) {
return [pos + 1];
}
// Compare by local name, ignoring any namespace prefix on either side.
const particleColon = this.name.indexOf(':');
const childColon = childName.indexOf(':');
const particleLocal = particleColon !== -1 ? this.name.substring(particleColon + 1) : this.name;
const childLocal = childColon !== -1 ? childName.substring(childColon + 1) : childName;
if (particleLocal === childLocal) {
return [pos + 1];
}
// Check substitution group members.
for (const altName of this.additionalNames) {
const altColon = altName.indexOf(':');
const altLocal = altColon !== -1 ? altName.substring(altColon + 1) : altName;
if (childLocal === altLocal) {
return [pos + 1];
}
}
return [];
}
}
//# sourceMappingURL=SchemaElementParticle.js.map