Skip to content

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.

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);
import { readFile } from 'node:fs/promises';
import { parseArchiModel } from '@cda/archi-semantic-core';
const xml = await readFile('MyModel.archimate', 'utf8');
const model = parseArchiModel(xml);

parseArchiModel returns an ArchiModel whose collections are flat arrays in source-XML order:

CollectionContents
foldersThe model tree (Business, Application, Relations, Views, custom folders).
elementsAll semantic elements, any ArchiMate type.
relationshipsAll semantic relationships.
viewsAll diagram/view definitions.
diagramObjectsVisual nodes: diagram objects, groups, model references.
diagramConnectionsVisual connections between diagram objects.
notesFree-text diagram notes.
profilesSpecializations 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).

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.