[owslibjs] Using Jsonix for OWS
Aleksei Valikov
valikov at gmx.net
Sun Aug 17 11:30:41 PDT 2014
Hi everyone,
I'd like to introduce my open-source JS library, Jsonix (
https://github.com/highsource/jsonix) which - in my opinion suits very well
for OWS needs.
Jsonix stands for "JSON interfaces for XML" and allows converting between
JSON and XML in certain schema with no pain.
Here's a small code example to demonstrate what it looks like:
// First we construct a Jsonix context - a factory for unmarshaller
(parser)// and marshaller (serializer)var context = new
Jsonix.Context([PO]);
// Then we create a unmarshallervar unmarshaller = context.createUnmarshaller();
// Unmarshal an object from the XML retrieved from the
URLunmarshaller.unmarshalURL('po.xml',
// This callback function will be provided
// with the result of the unmarshalling
function (unmarshalled) {
// Alice Smith
console.log(unmarshalled.value.shipTo.name);
// Baby Monitor
console.log(unmarshalled.value.items.item[1].productName);
});
You can try it online in JSFiddle: http://jsfiddle.net/lexi/LP3DC/
Jsonix is schema-driven. You can basically take an XML Schema and compile
it into JSON-XML mappings.
Jsonix will then be able to unmarshal XML into JSON which is very easy to
process in JavaScript programs.
You can also marshal JSON into XML so you're getting the full XML<->JSON
rountrip for free.
Java developers out there will defintely recognize similarities to JAXB.
Jsonix is basically a JAXB analog for JavaScript.
I wrote Jsonix with OGC Schemas in mind.
Here's a WMS demo:
https://github.com/highsource/jsonix/tree/master/demos/wms
Here's a sample WPS project:
https://github.com/highsource/jsonix/tree/master/nodejs/tests/wps
So if you need a reliable, schema-driven, strongly-typed and structured
XML-JSON conversion for you target OGC spec, you can take Jsonix, compile
your schema and save all those gory XML-to-JSON-and-back details, just
concentrate on your payload in a neat predictable JSON form.
Jsonix works in most browsers (browser protability is ~ OpenLayers).
Works with node.js. Works with RequireJS. No conflicts with OpenLayers.
Open-source (3-clause BSD), no strings attached.
Heavily tested.
I'd be very glad if you consider using Jsonix for OWS. I'd be happy to
provide support and help as much as I can.
Best wishes,
Alexey Valikov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/owsjs/attachments/20140817/b2b53a97/attachment.html>
More information about the Owsjs
mailing list