Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

moddle-xml

Package Overview
Dependencies
Maintainers
2
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moddle-xml

XML import/export for documents described with moddle

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
50K
decreased by-44.8%
Maintainers
2
Weekly downloads
 
Created
Source

moddle-xml

XML import/export for documents described with moddle.

Usage

Get the libray via npm

npm install --save moddle-xml
Bootstrap

Instantiate a moddle instance

var Moddle = require('moddle'),
    ModdleXML = require('moddle-xml');

var model = new Moddle([ myPackage ]);
Read XML

Use the reader to parse XML into an object tree that represents your model descriptor:

var model; // previously created

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

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

// when
reader.fromXML(xml, rootHandler, function(err, cars, context) {

  if (err) {
    console.log('import error', err);
  } else {

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

    console.log(cars);

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

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 ModdleXML.Writer(options);

var xml = writer.toXML(bar);

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

License

MIT

Keywords

FAQs

Package last updated on 19 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc