パッケージの詳細

moddle-xml

bpmn-io474.5kMIT11.0.0

XML import/export for documents described with moddle

moddle, model, meta-model, xml

readme

moddle-xml

CI

Read and write XML documents described with moddle.

Usage

Get the libray via npm

npm install --save moddle-xml

Bootstrap

Create a moddle instance

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:

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:

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

更新履歴

Changelog

All notable changes to moddle-xml are documented here. We use semantic versioning for releases.

Unreleased

_Note: Yet to be released changes appear here._

11.0.0

  • FEAT: add package exports (#73)
  • FEAT: access :xmlns as a global name (#69, bdb5824)
  • FEAT: allow to configure custom namespace map (#69, 17d8cb0)
  • FEAT: support alternative serialization methods (#69, 2cb16b2)
  • FIX: correct export of generic element (#69, 235504f)
  • FIX: remove broken main configuration (#73)
  • CHORE: drop UMD distribution (#73)
  • DEPS: update to min-dash@4.2.1
  • DEPS: update to min-dash@4.2.1
  • DEPS: update to saxen@10
  • DEPS: update to moddle@7

Breaking Changes

  • UMD distribution no longer bundled. The module is now available as an ES module.

10.1.0

  • FEAT: generate sourcemaps

10.0.0

  • DEPS: update to min-dash@4
  • DEPS: update to moddle@6
  • CHORE: turn into ES module

9.0.6

  • FIX: correctly handle duplicated attributes (#66)

9.0.5

  • FIX: correct serialization of xml namespace attributes on Any elements (#60)
  • FIX: do not trim non-empty element text (#58)

9.0.4

  • FIX: make hasOwnProperty check safe (#54)

9.0.3

  • FIX: handle default xml namespace (#50)

8.0.8

  • FIX: handle default xml namespace

9.0.2

  • FIX: recursively log namespace as used (#49)

8.0.7

  • FIX: recursively log namespace as used (#49)

9.0.1

  • FIX: correctly serialize nested local namespaced elements (#47)

8.0.6

  • FIX: correctly serialize nested local namespaced elements (#48)

9.0.0

  • FEAT: promisify Reader#fromXML (#45)

Breaking Changes

  • Reader#fromXML API now returns a Promise. Support for callbacks is dropped. Refer to the documentation for updated usage information.

8.0.5

Republish of v8.0.4.

8.0.4

  • CHORE: bump to saxen@8.1.2

8.0.3

  • CHORE: bump to saxen@8.1.1

8.0.2

  • FIX: read element as type if conflicting named propery is defines an attribute (#43)

8.0.1

  • DOCS: update documentation

8.0.0

  • FEAT: provide pre-packaged distribution
  • CHORE: bump to moddle@5

7.5.0

  • FEAT: validate ID attributes are QNames

7.4.1

  • FIX: make ES5 compliant

7.4.0

  • CHORE: get rid of tiny-stack as a dependency (#38)

7.3.0

  • FEAT: warn on unexpected body text
  • FEAT: warn on text outside root node
  • CHORE: remove console.log during import (#28)
  • CHORE: bump to saxen@8.1.0

7.2.3

  • FIX: correctly serialize extension attributes along with typed elements

7.2.0

  • FEAT: warn on invalid attributes under well-known namespaces (#32)

7.1.0

  • CHORE: bump dependency versions

7.0.0

Breaking Changes

  • FEAT: migrate to ES modules. Use esm or a ES module aware transpiler to consume this library.

6.0.0

  • FEAT: encode entities in body properties (instead of escaping via CDATA) (5645b582)

5.0.2

  • FIX: properly handle . in attribute names

5.0.1

  • FIX: decode entities in text nodes

5.0.0

  • FEAT: replace lodash with min-dash
  • FEAT: don't bail out from attribute parsing on parse errors (fd0c8b40)

...

Check git log for earlier history.