Parse your first model
parseArchiModel accepts XML text only. Reading a file from disk, using
the browser File API, or fetching XML over the network is the caller’s
responsibility — this keeps the package usable from Node.js, browser bundlers,
and tests without coupling it to a specific I/O environment.
Minimal example
Section titled “Minimal example”import { parseArchiModel, validateArchiModel,} from '@cda/archi-semantic-core';
const model = parseArchiModel(xml);
console.log(model.elements);console.log(model.relationships);console.log(model.views);
console.log(model.elements[0].type);// e.g. "ApplicationComponent", not "archimate:ApplicationComponent"
const { valid, errors } = validateArchiModel(model);Reading from disk
Section titled “Reading from disk”import { readFile } from 'node:fs/promises';import { parseArchiModel } from '@cda/archi-semantic-core';
const xml = await readFile('MyModel.archimate', 'utf8');const model = parseArchiModel(xml);What you get back
Section titled “What you get back”parseArchiModel returns an ArchiModel
whose collections are flat arrays in source-XML order:
| Collection | Contents |
|---|---|
folders | The model tree (Business, Application, Relations, Views, custom folders). |
elements | All semantic elements, any ArchiMate type. |
relationships | All semantic relationships. |
views | All diagram/view definitions. |
diagramObjects | Visual nodes: diagram objects, groups, model references. |
diagramConnections | Visual connections between diagram objects. |
notes | Free-text diagram notes. |
profiles | Specializations and generic Profiles declared at the model root. |
Cross-references between collections are plain string ids — look them up in
the relevant array, or build a Map keyed by id for repeated lookups
(see Build lookup indexes).
Error behavior
Section titled “Error behavior”parseArchiModel throws when:
- the input is not a string;
- the XML is not well formed.
It does not throw for a semantically broken model (missing ids, dangling
references, unresolved Junction values) — use
validateArchiModel for structural checks.