moddle-xml
XML import/export for documents described with moddle
Last updated 10 years ago by nikku .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install moddle-xml 
SYNC missed versions from official npm registry.

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

Current Tags

  • 10.1.0                                ...           latest (2 years ago)
  • 11.0.0-exp.4                                ...           next (2 years ago)

74 Versions

  • 11.0.0-exp.4                                ...           2 years ago
  • 11.0.0-exp.3                                ...           2 years ago
  • 11.0.0-exp.2                                ...           2 years ago
  • 11.0.0-exp.1                                ...           2 years ago
  • 10.1.0                                ...           2 years ago
  • 11.0.0-exp.0                                ...           2 years ago
  • 10.0.0                                ...           2 years ago
  • 9.0.6                                ...           2 years ago
  • 9.0.5                                ...           4 years ago
  • 9.0.4                                ...           4 years ago
  • 9.0.3                                ...           5 years ago
  • 8.0.8                                ...           5 years ago
  • 9.0.2                                ...           5 years ago
  • 8.0.7                                ...           5 years ago
  • 9.0.1                                ...           5 years ago
  • 8.0.6                                ...           5 years ago
  • 8.0.5                                ...           5 years ago
  • 9.0.0                                ...           5 years ago
  • 8.0.3                                ...           5 years ago
  • 8.0.2                                ...           5 years ago
  • 8.0.1                                ...           6 years ago
  • 8.0.0                                ...           6 years ago
  • 7.5.0                                ...           6 years ago
  • 7.4.1                                ...           6 years ago
  • 7.4.0                                ...           6 years ago
  • 7.3.0                                ...           6 years ago
  • 7.2.3                                ...           7 years ago
  • 7.2.2                                ...           7 years ago
  • 7.2.1                                ...           7 years ago
  • 7.2.0                                ...           7 years ago
  • 7.1.0                                ...           7 years ago
  • 7.0.0                                ...           7 years ago
  • 6.0.0                                ...           7 years ago
  • 5.0.2                                ...           7 years ago
  • 5.0.1                                ...           7 years ago
  • 5.0.0                                ...           7 years ago
  • 4.1.4                                ...           7 years ago
  • 4.1.3                                ...           7 years ago
  • 4.1.2                                ...           7 years ago
  • 4.1.1                                ...           7 years ago
  • 4.1.0                                ...           7 years ago
  • 4.0.0                                ...           7 years ago
  • 3.0.0                                ...           7 years ago
  • 2.2.0                                ...           7 years ago
  • 2.1.1                                ...           7 years ago
  • 2.1.0                                ...           7 years ago
  • 2.0.2                                ...           7 years ago
  • 2.0.1                                ...           7 years ago
  • 2.0.0                                ...           7 years ago
  • 1.1.1                                ...           7 years ago
  • 1.1.0                                ...           7 years ago
  • 1.0.0                                ...           8 years ago
  • 0.12.0                                ...           9 years ago
  • 0.11.1                                ...           9 years ago
  • 0.11.0                                ...           9 years ago
  • 0.10.0                                ...           9 years ago
  • 0.9.4                                ...           9 years ago
  • 0.9.3                                ...           9 years ago
  • 0.9.2                                ...           9 years ago
  • 0.9.1                                ...           9 years ago
  • 0.9.0                                ...           9 years ago
  • 0.8.0                                ...           10 years ago
  • 0.7.0                                ...           10 years ago
  • 0.6.0                                ...           10 years ago
  • 0.5.1                                ...           10 years ago
  • 0.5.0                                ...           10 years ago
  • 0.4.1                                ...           10 years ago
  • 0.4.0                                ...           10 years ago
  • 0.3.0                                ...           10 years ago
  • 0.2.0                                ...           11 years ago
  • 0.1.0                                ...           11 years ago
  • 0.0.4                                ...           11 years ago
  • 0.0.3                                ...           11 years ago
  • 0.0.2                                ...           11 years ago
Downloads
Today 0
This Week 0
This Month 71
Last Day 0
Last Week 0
Last Month 0
Dependencies (4)
Dev Dependencies (10)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |