# moddle-xml

> XML import/export for documents described with moddle

Latest version **12.2.0** (published 2026-08-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install moddle-xml
pnpm add moddle-xml
yarn add moddle-xml
bun add moddle-xml
```

## Health

**Score 60/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 12.2.0 |
| Published | 2026-08-25 |
| First published | 2014-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | >= 18 |
| Dependencies | 2 |
| Unpacked size | 143.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 54 |
| Author | Nico Rehwaldt |
| Maintainers | bpmn-io-admin, nikku, barmac, philippfromme, maxtru, skaiir-camunda, vsgoulart, barinali, ev-camunda, jarekdanielak, alekseymanetov |
| Keywords | moddle, model, meta-model, xml, xsd, import, export |

## Links

- npm: https://www.npmjs.com/package/moddle-xml
- Repository: https://github.com/bpmn-io/moddle-xml
- Homepage: https://github.com/bpmn-io/moddle-xml#readme
- Issues: https://github.com/bpmn-io/moddle-xml/issues
- npm.io page: https://npm.io/package/moddle-xml

## Dependencies (2)

- [saxen](https://npm.io/package/saxen.md) ^11.1.0
- [min-dash](https://npm.io/package/min-dash.md) ^5.1.0

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 12.2.0 (latest) — 2026-08-25
- 11.0.0-exp.4 (next) — 2023-02-24
- 12.1.0 — 2026-07-15
- 12.0.0 — 2026-01-16
- 11.0.0 — 2024-03-06
- 11.0.0-exp.3 — 2023-02-23
- 11.0.0-exp.2 — 2023-02-23
- 11.0.0-exp.1 — 2022-12-21
- 10.1.0 — 2022-12-18
- 11.0.0-exp.0 — 2022-12-17
- 10.0.0 — 2022-10-02
- 9.0.6 — 2022-08-22
- 9.0.5 — 2021-04-19
- 9.0.4 — 2020-12-02
- 9.0.3 — 2020-06-05
- … 63 more at https://npm.io/package/moddle-xml/versions

## README

# moddle-xml

[![CI](https://github.com/bpmn-io/moddle-xml/workflows/CI/badge.svg)](https://github.com/bpmn-io/moddle-xml/actions?query=workflow%3ACI)

Read and write XML documents described with [moddle](https://github.com/bpmn-io/moddle).


## Usage

Get the libray via [npm](http://npmjs.org)

```
npm install --save moddle-xml
```


#### Bootstrap

Create a [moddle instance](https://github.com/bpmn-io/moddle)

```javascript
import { Moddle } from 'moddle';
import {
  Reader,
  Writer
} from 'moddle-xml';

const model = new Moddle([ myPackage ]);
```


#### Read XML

Use the reader to parse XML into an easily accessible object tree:

```javascript
const model; // previously created

const xml =
  '<my:root xmlns:props="http://mypackage">' +
    '<my:car id="Car_1">' +
      '<my:engine power="121" fuelConsumption="10" />' +
    '</my:car>' +
  '</my:root>';

const reader = new Reader(model);
const rootHandler = reader.handler('my:Root');

// when
try {
  const {
    rootElement: cars,
    warnings
  } = await reader.fromXML(xml, rootHandler);

  if (warnings.length) {
    console.log('import warnings', warnings);
  }

  console.log(cars);

  // {
  //  $type: 'my:Root',
  //  cars: [
  //    {
  //      $type: 'my:Car',
  //      id: 'Car_1',
  //      engine: [
  //        { $type: 'my:Engine', powser: 121, fuelConsumption: 10 }
  //      ]
  //    }
  //  ]
  // }

} catch (err) {
  console.log('import error', err, err.warnings);
}
```


#### Write XML

Use the writer to serialize the object tree back to XML:

```javascript
var model; // previously created

var cars = model.create('my:Root');
cars.get('cars').push(model.create('my:Car', { power: 10 }));

var options = { format: false, preamble: false };
var writer = new Writer(options);

var xml = writer.toXML(bar);

console.log(xml); // <my:root xmlns:props="http://mypackage"> ... <my:car power="10" /></my:root>
```

## License

MIT

---
_Source: https://npm.io/package/moddle-xml · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
