diff()
typescript
function diff(
fromXml: string,
toXml: string,
options?: DiffOptions,
): DiffResultParses and semantically diffs two DMN XML strings.
Parameters
| Name | Type | Description |
|---|---|---|
fromXml | string | XML content of the "before" file |
toXml | string | XML content of the "after" file |
options | DiffOptions | Optional metadata |
DiffOptions
typescript
interface DiffOptions {
fromFile?: string // shown in meta and renderer headers
toFile?: string
}Returns
DiffResult — a structured object containing the summary, metadata, and list of changes.
Example
typescript
import { diff } from '@veridtools/dmn-diff'
const result = diff(beforeXml, afterXml, {
fromFile: 'v1.dmn',
toFile: 'v2.dmn',
})
console.log(result.meta.hasChanges) // boolean
console.log(result.summary.modified) // number
console.log(result.changes.length) // total number of changesAlgorithm
- Preprocess — remove BOM, expand CDATA to XML entities
- Parse — convert XML to a JavaScript object tree (namespace prefixes stripped)
- Normalize — apply defaults (
hitPolicy,isCollection,preferredOrientation), trim whitespace, remove DMNDI - Index — build
Map<id, element>by traversing the entire tree - Diff — for every ID in either model: added / removed / modified (with field-level comparison)
- LCS fallback — for unindexed elements (rules, bindings, contextEntries without IDs)
