Skip to content

Using W3C Schemas with Browserify

Alexey Valikov edited this page Apr 18, 2015 · 2 revisions

Using W3C Schemas with Browserify

  • Require jsonix,
  • Require w3c-schemas/lib/<Mapping>
  • Build browserify app.js -o bundle.js

Example

Let's assume we want to parse the XML Schema my.xsd in a JavaScript program. The w3c-schemas provide the XSD_1_0 mapping for XML Schema 1.0.

var Jsonix = require('jsonix').Jsonix;
var XSD_1_0 = require('w3c-schemas/lib/XSD_1_0').XSD_1_0;

var context = new Jsonix.Context([XSD_1_0], {
	namespacePrefixes: { 'http://www.w3.org/2001/XMLSchema': 'xlink' }
});
var unmarshaller = context.createUnmarshaller();

unmarshaller.unmarshalURL('my.xsd', function(result) {
	console.log(JSON.stringify(result, null, 2));
});