SlideShare a Scribd company logo
Talking to OGC Web Services
in JSON
Or How I Learned to Stop Worrying
and Love XML Processing in JavaScript
1
Hi, my name is …
Alexey Valikov
http://xing.to/va
https://github.com/highsource
@orless
2
… and I’m (also) into GIS and Web Mapping
GIS 2go
Internal apps for the Deutsche Bahn
3
Web Mapping means JavaScript
4
JavaScript speaks JSON
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
},
"properties": {
"name": "Dinagat Islands"
}
}
[ˈdʒeɪsən]
5
GIS-Services are based on OGC Standards
6
… specified by XML Schemas
More than 50 Schemas
More than 100 individual versions
Over 8MB and 800 individual XSD files
7
OGC Web Services speak XML
GetCapabilities
<wfs:WFS_Capabilities …
/>
GetFeature
<wfs:FeatureCollection …
/>
Client WFS Server
8
JS Apps have a communication problem
JS App WFS Server
{”JS”:”ON”} ???
XSD
9
<x:ml/>
Jsonix provides a solution
Mapping
10
WFS Server
{”JS”:”ON”}
Jsonix
XSD
<x:ml/>
JS App
What is Jsonix?
Jsonix is a powerful Open-Source JavaScript library
for XML↔JS conversion
https://github.com/highsource/jsonix
Bidirectional, type-safe, strongly-structured
Driven by declarative XML↔JS mappings…
… which can be generated from XML schemas
automatically
11
Further Jsonix features
Works in browsers
Works in Node.js
Works with AMD, CommonJS and without (globals)
Namespace-aware
Supports almost all of the XML Schema simple types
(including binary types and QNames)
Supports xsi:type
And much more
12
Jsonix Example
Parse WMS Capabilities
JSFiddle:
http://bit.do/jsonix-001
13
Parsing with Jsonix - Code Walk-Through
var getCapabilitiesUrl = …;
// First we create a context for XLink and WMS mappings
var context = new Jsonix.Context([XLink_1_0, WMS_1_3_0], …);
// Then we create an unmarshaller (parser)
var unmarshaller = context.createUnmarshaller();
// And finally use this unmarshaller
// to parse an XML document from the given URL
unmarshaller.unmarshalURL(getCapabilitiesUrl, function(result) {
// We’ll get results in a callback function
$('#json').html(JSON.stringify(result, null, 2));
});
14
Jsonix creates pretty JSON
<WMS_Capabilities …
version="1.3.0"
updateSequence="163">
<Service> … </Service>
<Capability>
<Request> … </Request>
<Exception> … </Exception>
<Layer>
…
<Layer queryable="1">…</Layer>
<Layer queryable="1" opaque="0">…</Layer>
…
</Layer>
</Capability>
</WMS_Capabilities>
{
"WMS_Capabilities": {
"version": "1.3.0",
"updateSequence": "163",
"service": { … },
"capability": {
"request": { … },
"exception": { … },
"layer": { … ,
"layer": [ … ]
}
}
}
}
15
… and can serialize this JSON back to XML
// Create (or reuse) the Jsonix Context
var context = new Jsonix.Context([XLink_1_0, WMS_1_3_0], …);
// Create a marshaller (serializer)
var marshaller = context.createMarshaller();
// Serialize JSON as XML string or DOM node
$('#xml').text(marshaller.marshalString(result));
16
The same thing without Jsonix?
OpenLayers 3: ol.format.
WMSCapabilities
JSFiddle:
http://bit.do/jsonix-002
17
Let’s take a closer look into the OL3 code
ol.format.WMSCapabilities
ca. 28 kB, ca 0.8 KLoC
Type-safe
Strongly-structured
Only parsing
Written manually
Super exciting code
18
Why yet another XML-JS tool?
19
Jsonix
is strongly-structured
and type-safe
And that’s unparalleled
20
What does “strongly-structured” mean?
<WMS_Capabilities …
version="1.3.0"
updateSequence="163">
<Service> … </Service>
<Capability>
<Request> … </Request>
<Exception> … </Exception>
<Layer> …
<!-- Just one Layer element -->
<Layer queryable="1"> … </Layer>
</Layer>
</Capability>
</WMS_Capabilities>
How should the Layer element
be represented in JSON?
As a single element or as an array?
capability.layer.layer?
capability.layer.layer[0]?
You can’t decide it just based on
the XML instance
You have to know the schema
21
Jsonix is strongly-structured
Jsonix knows the structure of the XML from the mapping
… and respects the defined cardinalities, element orders,
properties, naming and so on
Jsonix always produces JSON and XML-structures which
respect the definitions from the mapping
22
Jsonix produces reliable structures
<WMS_Capabilities …
version="1.3.0"
updateSequence="163">
<Service> … </Service>
<Capability>
<Request> … </Request>
<Exception> … </Exception>
<Layer> …
<Layer queryable="1"> … </Layer>
</Layer>
</Capability>
</WMS_Capabilities>
layer is an array:
capability.layer.layer[0]
Because the mapping says so:
23
Strong, reliable structures
===
simpler code
24
What does “type-safe” mean?
<WMS_Capabilities …
version="1.3.0"
updateSequence="163">
<Service> … </Service>
<Capability>
<Request> … </Request>
<Exception> … </Exception>
<Layer> …
<Layer queryable="1"> … </Layer>
</Layer>
</Capability>
</WMS_Capabilities>
Which type should
queryable=”1” have in JSON?
String? Number? Boolean?
You can’t decide it just based on
the XML instance
You have to know the schema
25
Jsonix is type-safe
Jsonix knows types of elements
and attributes from the mapping
… and converts strings from/to
these types automatically
Jsonix always produces values in
JSON and XML according to the
types defined in the mapping
26
Jsonix converts the types automatically
<WMS_Capabilities …
version="1.3.0"
updateSequence="163">
<Service> … </Service>
<Capability>
<Request> … </Request>
<Exception> … </Exception>
<Layer> …
<Layer queryable="1"> … </Layer>
</Layer>
</Capability>
</WMS_Capabilities>
queryable is a boolean:
{ "queryable" : true, … }
Because the mappings says so:
27
Safe, automatic type conversion
===
less work
28
Jsonix uses declarative mappings
Jsonix mappings are just descriptions of structures, not imperative programs
29
Mappings are essential
for strong structures
and safe typing
30
Jsonix can generate mappings from XSDs
Jsonix Runtime
XSD
Mapping
Jsonix Schema Compiler
{“JS”:”ON”} <x:ml/>
31
..as follows
java -jar jsonix-schema-compiler.jar
-catalog schemas/catalog.cat
schemas/ogc/wms/1.3.0/capabilities_1_3_0.xsd
-b schemas
-d mappings
Generates Jsonix mappings for WMS 1.3.0:
WMS_1_3_0_Full.js
GitHub:
http://bit.do/jsonix-006
32
Experimental: Generate JSON Schemas from XSDs
Jsonix Runtime
XSD
Mapping
Jsonix Schema Compiler
{“JS”:”ON”} <x:ml/>
33
JSON
Schema
Experimental java -jar jsonix-schema-compiler.jar
-generateJsonSchema …
Experimental: Validate JSON against generated JSON Schemas
Using the great “Another JSON Schema Validator” AJV
// Load JSON Schemas
var ajv = new Ajv();
ajv.addSchema(XMLSchemaJsonSchema, … ); ajv.addSchema(JsonixJsonSchema, … );
ajv.addSchema(XLink_1_0JsonSchema, 'http://www.w3.org/1999/xlink');
// Compile the validation function and validate
var validate = ajv.compile(WMS_1_3_0JsonSchema);
if (!validate(capabilitiesElement)) { console.log(validate.errors); }
34
[{
keyword: 'required',
dataPath: '.value.capability.request.getCapabilities.dcpType['0'].http',
message: 'property .http is required'
}, … ]
Compiling XSDs into mappings is hard
35
By
Alex
E.
Proimos
(http://www.flickr.
com/photos/proimos/4199675334/)
[CC
BY
2.0
(http://creativecommons.org/licenses/by/2.0)],
via
Wikimedia
Commons
Compiling XSDs into mappings is hard
We’ve huge number of schemas with complex
interdependencies
Schemas sometimes have errors
We have to resolve naming collisions
We’re often forced to customize generation or even
patch schemas
36
(Unofficial) OGC Schemas Project
https://github.com/highsource/ogc-schemas
Pre-generated mapping for OGC Schemas:
JS↔XML: Jsonix mappings
Java↔XML: JAXB classes
Available via npmjs.org and Maven Central
37
(Unofficial) OGC Schemas Project
Compiles over 30 OGC Schemas
with more than 80 single versions
OWS, WMS, SLD, GML, Filter,
WFS, WPS, WCS, WMC, SWE,
SPS, SOS, OM, SensorML, KML,
ISO 19139, CSW, and many
more…
… ready-to-use with Jsonix
38
Using pre-generated mappings
var mappings = [XLink_1_0, SMIL_2_0, SMIL_2_0_Language,
GML_3_1_1, OWS_1_0_0, Filter_1_1_0, DC_1_1, DCT, CSW_2_0_2];
// Create a Jsonix context
var context = new Jsonix.Context(mappings, {
namespacePrefixes: {
"http://www.opengis.net/cat/csw/2.0.2": "csw",
"http://www.opengis.net/ogc": "ogc",
"http://www.opengis.net/gml": "gml"
}
});
JSFiddle:
http://bit.do/jsonix-007
39
Takeaway
Jsonix is a powerful Open-Source JavaScript library for
XML↔JS conversion
Works in browsers as well as Node.js
Bidirectional, strongly-structured and type-safe
Uses declarative XML↔JS mappings
Mappings can be generated from XML Schemas
The (unofficial) OGC Schemas Project provides ready-to-use
pre-generated mapping for many OGC Schemas
40
Jsonix can drastically simplify
XML processing in JavaScript apps
and thus save a lot of development effort
https://github.com/highsource/jsonix
41

More Related Content

What's hot

Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and Python
Mike Bright
 
Synapseindia dot net development web applications with ajax
Synapseindia dot net development  web applications with ajaxSynapseindia dot net development  web applications with ajax
Synapseindia dot net development web applications with ajax
Synapseindiappsdevelopment
 
Mysql to mongo
Mysql to mongoMysql to mongo
Mysql to mongo
Alex Sharp
 
MongoDB - How to model and extract your data
MongoDB - How to model and extract your dataMongoDB - How to model and extract your data
MongoDB - How to model and extract your data
Francesco Lo Franco
 
Using Mongoid with Ruby on Rails
Using Mongoid with Ruby on RailsUsing Mongoid with Ruby on Rails
Using Mongoid with Ruby on Rails
Nicholas Altobelli
 
Introduction towebmatrix
Introduction towebmatrixIntroduction towebmatrix
Introduction towebmatrix
Pranav Ainavolu
 
MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Railsrfischer20
 
Mongoid in the real world
Mongoid in the real worldMongoid in the real world
Mongoid in the real worldKevin Faustino
 
Railswaycon Inside Matz Ruby
Railswaycon Inside Matz RubyRailswaycon Inside Matz Ruby
Railswaycon Inside Matz Ruby
Lourens Naudé
 
Mastering the MongoDB Shell
Mastering the MongoDB ShellMastering the MongoDB Shell
Mastering the MongoDB Shell
MongoDB
 
JSONSchema with golang
JSONSchema with golangJSONSchema with golang
JSONSchema with golang
Suraj Deshmukh
 
Tapestry 5: Java Power, Scripting Ease
Tapestry 5: Java Power, Scripting EaseTapestry 5: Java Power, Scripting Ease
Tapestry 5: Java Power, Scripting Ease
Howard Lewis Ship
 

What's hot (15)

Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and Python
 
Synapseindia dot net development web applications with ajax
Synapseindia dot net development  web applications with ajaxSynapseindia dot net development  web applications with ajax
Synapseindia dot net development web applications with ajax
 
Mysql to mongo
Mysql to mongoMysql to mongo
Mysql to mongo
 
MongoDB - How to model and extract your data
MongoDB - How to model and extract your dataMongoDB - How to model and extract your data
MongoDB - How to model and extract your data
 
Using Mongoid with Ruby on Rails
Using Mongoid with Ruby on RailsUsing Mongoid with Ruby on Rails
Using Mongoid with Ruby on Rails
 
Introduction towebmatrix
Introduction towebmatrixIntroduction towebmatrix
Introduction towebmatrix
 
Linq
LinqLinq
Linq
 
MongoDB and Ruby on Rails
MongoDB and Ruby on RailsMongoDB and Ruby on Rails
MongoDB and Ruby on Rails
 
Mongoid in the real world
Mongoid in the real worldMongoid in the real world
Mongoid in the real world
 
Railswaycon Inside Matz Ruby
Railswaycon Inside Matz RubyRailswaycon Inside Matz Ruby
Railswaycon Inside Matz Ruby
 
Mastering the MongoDB Shell
Mastering the MongoDB ShellMastering the MongoDB Shell
Mastering the MongoDB Shell
 
Web service introduction
Web service introductionWeb service introduction
Web service introduction
 
JSONSchema with golang
JSONSchema with golangJSONSchema with golang
JSONSchema with golang
 
Tapestry 5: Java Power, Scripting Ease
Tapestry 5: Java Power, Scripting EaseTapestry 5: Java Power, Scripting Ease
Tapestry 5: Java Power, Scripting Ease
 
Codemash-Tapestry.pdf
Codemash-Tapestry.pdfCodemash-Tapestry.pdf
Codemash-Tapestry.pdf
 

Viewers also liked

A Database for Every Occasion
A Database for Every OccasionA Database for Every Occasion
A Database for Every Occasion
Safe Software
 
Remote Sensing Data — Instant Home Delivery!
Remote Sensing Data — Instant Home Delivery!Remote Sensing Data — Instant Home Delivery!
Remote Sensing Data — Instant Home Delivery!
Safe Software
 
Ultimate Real-Time — Monitor Anything, Update Anything
Ultimate Real-Time — Monitor Anything, Update AnythingUltimate Real-Time — Monitor Anything, Update Anything
Ultimate Real-Time — Monitor Anything, Update Anything
Safe Software
 
Integrating Web and Business Data
Integrating Web and Business DataIntegrating Web and Business Data
Integrating Web and Business Data
Safe Software
 
Deep Dive into FME Server 2017.0
Deep Dive into FME Server 2017.0Deep Dive into FME Server 2017.0
Deep Dive into FME Server 2017.0
Safe Software
 
Load testing of HELIDEM geo-portal: an OGC open standards interoperability ex...
Load testing of HELIDEM geo-portal: an OGC open standards interoperability ex...Load testing of HELIDEM geo-portal: an OGC open standards interoperability ex...
Load testing of HELIDEM geo-portal: an OGC open standards interoperability ex...
Massimiliano Cannata
 

Viewers also liked (6)

A Database for Every Occasion
A Database for Every OccasionA Database for Every Occasion
A Database for Every Occasion
 
Remote Sensing Data — Instant Home Delivery!
Remote Sensing Data — Instant Home Delivery!Remote Sensing Data — Instant Home Delivery!
Remote Sensing Data — Instant Home Delivery!
 
Ultimate Real-Time — Monitor Anything, Update Anything
Ultimate Real-Time — Monitor Anything, Update AnythingUltimate Real-Time — Monitor Anything, Update Anything
Ultimate Real-Time — Monitor Anything, Update Anything
 
Integrating Web and Business Data
Integrating Web and Business DataIntegrating Web and Business Data
Integrating Web and Business Data
 
Deep Dive into FME Server 2017.0
Deep Dive into FME Server 2017.0Deep Dive into FME Server 2017.0
Deep Dive into FME Server 2017.0
 
Load testing of HELIDEM geo-portal: an OGC open standards interoperability ex...
Load testing of HELIDEM geo-portal: an OGC open standards interoperability ex...Load testing of HELIDEM geo-portal: an OGC open standards interoperability ex...
Load testing of HELIDEM geo-portal: an OGC open standards interoperability ex...
 

Similar to Jsonix - Talking to OGC Web Services in JSON

WebSocket JSON Hackday
WebSocket JSON HackdayWebSocket JSON Hackday
WebSocket JSON HackdaySomay Nakhal
 
WSO2 Advantage Webinar - JSON Support in the WSO2 Platform
WSO2 Advantage Webinar -  JSON Support in the WSO2 PlatformWSO2 Advantage Webinar -  JSON Support in the WSO2 Platform
WSO2 Advantage Webinar - JSON Support in the WSO2 PlatformWSO2
 
JBossWS Project by Alessio Soldano
JBossWS Project by Alessio SoldanoJBossWS Project by Alessio Soldano
JBossWS Project by Alessio Soldano
Java User Group Roma
 
April 2010 - JBoss Web Services
April 2010 - JBoss Web ServicesApril 2010 - JBoss Web Services
April 2010 - JBoss Web ServicesJBug Italy
 
MySQL as a Document Store
MySQL as a Document StoreMySQL as a Document Store
MySQL as a Document Store
Dave Stokes
 
MunichJS - 2011-04-06
MunichJS - 2011-04-06MunichJS - 2011-04-06
MunichJS - 2011-04-06
Mike West
 
Jim Manico: Developer Top 10 Core Controls, web application security @ OWASP ...
Jim Manico: Developer Top 10 Core Controls, web application security @ OWASP ...Jim Manico: Developer Top 10 Core Controls, web application security @ OWASP ...
Jim Manico: Developer Top 10 Core Controls, web application security @ OWASP ...Xlator
 
Scala js (kyiv js 30-01)
Scala js (kyiv js 30-01)Scala js (kyiv js 30-01)
Scala js (kyiv js 30-01)
Eugene Safronov
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web Application
Yakov Fain
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
Mike Brevoort
 
Going Native: Leveraging the New JSON Native Datatype in Oracle 21c
Going Native: Leveraging the New JSON Native Datatype in Oracle 21cGoing Native: Leveraging the New JSON Native Datatype in Oracle 21c
Going Native: Leveraging the New JSON Native Datatype in Oracle 21c
Jim Czuprynski
 
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScriptJavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
Dave Stokes
 
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Codemotion
 
Building HTTP API's with NodeJS and MongoDB
Building HTTP API's with NodeJS and MongoDBBuilding HTTP API's with NodeJS and MongoDB
Building HTTP API's with NodeJS and MongoDB
donnfelker
 
Maven + Jsf + Richfaces + Jxl + Jdbc - Complete Code Example
Maven + Jsf + Richfaces + Jxl + Jdbc - Complete Code ExampleMaven + Jsf + Richfaces + Jxl + Jdbc - Complete Code Example
Maven + Jsf + Richfaces + Jxl + Jdbc - Complete Code Example
Nikhil Bhalwankar
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
Domenic Denicola
 
XPages Blast - ILUG 2010
XPages Blast - ILUG 2010XPages Blast - ILUG 2010
XPages Blast - ILUG 2010
Tim Clark
 
Declarative and standards-based web application development with the Ample SDK
Declarative and standards-based web application development with the Ample SDKDeclarative and standards-based web application development with the Ample SDK
Declarative and standards-based web application development with the Ample SDK
Béla Varga
 
The Future of Web Attacks - CONFidence 2010
The Future of Web Attacks - CONFidence 2010The Future of Web Attacks - CONFidence 2010
The Future of Web Attacks - CONFidence 2010Mario Heiderich
 

Similar to Jsonix - Talking to OGC Web Services in JSON (20)

WebSocket JSON Hackday
WebSocket JSON HackdayWebSocket JSON Hackday
WebSocket JSON Hackday
 
WSO2 Advantage Webinar - JSON Support in the WSO2 Platform
WSO2 Advantage Webinar -  JSON Support in the WSO2 PlatformWSO2 Advantage Webinar -  JSON Support in the WSO2 Platform
WSO2 Advantage Webinar - JSON Support in the WSO2 Platform
 
JBossWS Project by Alessio Soldano
JBossWS Project by Alessio SoldanoJBossWS Project by Alessio Soldano
JBossWS Project by Alessio Soldano
 
April 2010 - JBoss Web Services
April 2010 - JBoss Web ServicesApril 2010 - JBoss Web Services
April 2010 - JBoss Web Services
 
MySQL as a Document Store
MySQL as a Document StoreMySQL as a Document Store
MySQL as a Document Store
 
MunichJS - 2011-04-06
MunichJS - 2011-04-06MunichJS - 2011-04-06
MunichJS - 2011-04-06
 
Jim Manico: Developer Top 10 Core Controls, web application security @ OWASP ...
Jim Manico: Developer Top 10 Core Controls, web application security @ OWASP ...Jim Manico: Developer Top 10 Core Controls, web application security @ OWASP ...
Jim Manico: Developer Top 10 Core Controls, web application security @ OWASP ...
 
Play framework
Play frameworkPlay framework
Play framework
 
Scala js (kyiv js 30-01)
Scala js (kyiv js 30-01)Scala js (kyiv js 30-01)
Scala js (kyiv js 30-01)
 
Seven Versions of One Web Application
Seven Versions of One Web ApplicationSeven Versions of One Web Application
Seven Versions of One Web Application
 
Node.js - async for the rest of us.
Node.js - async for the rest of us.Node.js - async for the rest of us.
Node.js - async for the rest of us.
 
Going Native: Leveraging the New JSON Native Datatype in Oracle 21c
Going Native: Leveraging the New JSON Native Datatype in Oracle 21cGoing Native: Leveraging the New JSON Native Datatype in Oracle 21c
Going Native: Leveraging the New JSON Native Datatype in Oracle 21c
 
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScriptJavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
JavaScript and Friends August 20th, 20201 -- MySQL Shell and JavaScript
 
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
 
Building HTTP API's with NodeJS and MongoDB
Building HTTP API's with NodeJS and MongoDBBuilding HTTP API's with NodeJS and MongoDB
Building HTTP API's with NodeJS and MongoDB
 
Maven + Jsf + Richfaces + Jxl + Jdbc - Complete Code Example
Maven + Jsf + Richfaces + Jxl + Jdbc - Complete Code ExampleMaven + Jsf + Richfaces + Jxl + Jdbc - Complete Code Example
Maven + Jsf + Richfaces + Jxl + Jdbc - Complete Code Example
 
The State of JavaScript
The State of JavaScriptThe State of JavaScript
The State of JavaScript
 
XPages Blast - ILUG 2010
XPages Blast - ILUG 2010XPages Blast - ILUG 2010
XPages Blast - ILUG 2010
 
Declarative and standards-based web application development with the Ample SDK
Declarative and standards-based web application development with the Ample SDKDeclarative and standards-based web application development with the Ample SDK
Declarative and standards-based web application development with the Ample SDK
 
The Future of Web Attacks - CONFidence 2010
The Future of Web Attacks - CONFidence 2010The Future of Web Attacks - CONFidence 2010
The Future of Web Attacks - CONFidence 2010
 

Recently uploaded

GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 

Recently uploaded (20)

GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Assure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyesAssure Contact Center Experiences for Your Customers With ThousandEyes
Assure Contact Center Experiences for Your Customers With ThousandEyes
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 

Jsonix - Talking to OGC Web Services in JSON

  • 1. Talking to OGC Web Services in JSON Or How I Learned to Stop Worrying and Love XML Processing in JavaScript 1
  • 2. Hi, my name is … Alexey Valikov http://xing.to/va https://github.com/highsource @orless 2
  • 3. … and I’m (also) into GIS and Web Mapping GIS 2go Internal apps for the Deutsche Bahn 3
  • 4. Web Mapping means JavaScript 4
  • 5. JavaScript speaks JSON { "type": "Feature", "geometry": { "type": "Point", "coordinates": [125.6, 10.1] }, "properties": { "name": "Dinagat Islands" } } [ˈdʒeɪsən] 5
  • 6. GIS-Services are based on OGC Standards 6
  • 7. … specified by XML Schemas More than 50 Schemas More than 100 individual versions Over 8MB and 800 individual XSD files 7
  • 8. OGC Web Services speak XML GetCapabilities <wfs:WFS_Capabilities … /> GetFeature <wfs:FeatureCollection … /> Client WFS Server 8
  • 9. JS Apps have a communication problem JS App WFS Server {”JS”:”ON”} ??? XSD 9 <x:ml/>
  • 10. Jsonix provides a solution Mapping 10 WFS Server {”JS”:”ON”} Jsonix XSD <x:ml/> JS App
  • 11. What is Jsonix? Jsonix is a powerful Open-Source JavaScript library for XML↔JS conversion https://github.com/highsource/jsonix Bidirectional, type-safe, strongly-structured Driven by declarative XML↔JS mappings… … which can be generated from XML schemas automatically 11
  • 12. Further Jsonix features Works in browsers Works in Node.js Works with AMD, CommonJS and without (globals) Namespace-aware Supports almost all of the XML Schema simple types (including binary types and QNames) Supports xsi:type And much more 12
  • 13. Jsonix Example Parse WMS Capabilities JSFiddle: http://bit.do/jsonix-001 13
  • 14. Parsing with Jsonix - Code Walk-Through var getCapabilitiesUrl = …; // First we create a context for XLink and WMS mappings var context = new Jsonix.Context([XLink_1_0, WMS_1_3_0], …); // Then we create an unmarshaller (parser) var unmarshaller = context.createUnmarshaller(); // And finally use this unmarshaller // to parse an XML document from the given URL unmarshaller.unmarshalURL(getCapabilitiesUrl, function(result) { // We’ll get results in a callback function $('#json').html(JSON.stringify(result, null, 2)); }); 14
  • 15. Jsonix creates pretty JSON <WMS_Capabilities … version="1.3.0" updateSequence="163"> <Service> … </Service> <Capability> <Request> … </Request> <Exception> … </Exception> <Layer> … <Layer queryable="1">…</Layer> <Layer queryable="1" opaque="0">…</Layer> … </Layer> </Capability> </WMS_Capabilities> { "WMS_Capabilities": { "version": "1.3.0", "updateSequence": "163", "service": { … }, "capability": { "request": { … }, "exception": { … }, "layer": { … , "layer": [ … ] } } } } 15
  • 16. … and can serialize this JSON back to XML // Create (or reuse) the Jsonix Context var context = new Jsonix.Context([XLink_1_0, WMS_1_3_0], …); // Create a marshaller (serializer) var marshaller = context.createMarshaller(); // Serialize JSON as XML string or DOM node $('#xml').text(marshaller.marshalString(result)); 16
  • 17. The same thing without Jsonix? OpenLayers 3: ol.format. WMSCapabilities JSFiddle: http://bit.do/jsonix-002 17
  • 18. Let’s take a closer look into the OL3 code ol.format.WMSCapabilities ca. 28 kB, ca 0.8 KLoC Type-safe Strongly-structured Only parsing Written manually Super exciting code 18
  • 19. Why yet another XML-JS tool? 19
  • 21. What does “strongly-structured” mean? <WMS_Capabilities … version="1.3.0" updateSequence="163"> <Service> … </Service> <Capability> <Request> … </Request> <Exception> … </Exception> <Layer> … <!-- Just one Layer element --> <Layer queryable="1"> … </Layer> </Layer> </Capability> </WMS_Capabilities> How should the Layer element be represented in JSON? As a single element or as an array? capability.layer.layer? capability.layer.layer[0]? You can’t decide it just based on the XML instance You have to know the schema 21
  • 22. Jsonix is strongly-structured Jsonix knows the structure of the XML from the mapping … and respects the defined cardinalities, element orders, properties, naming and so on Jsonix always produces JSON and XML-structures which respect the definitions from the mapping 22
  • 23. Jsonix produces reliable structures <WMS_Capabilities … version="1.3.0" updateSequence="163"> <Service> … </Service> <Capability> <Request> … </Request> <Exception> … </Exception> <Layer> … <Layer queryable="1"> … </Layer> </Layer> </Capability> </WMS_Capabilities> layer is an array: capability.layer.layer[0] Because the mapping says so: 23
  • 25. What does “type-safe” mean? <WMS_Capabilities … version="1.3.0" updateSequence="163"> <Service> … </Service> <Capability> <Request> … </Request> <Exception> … </Exception> <Layer> … <Layer queryable="1"> … </Layer> </Layer> </Capability> </WMS_Capabilities> Which type should queryable=”1” have in JSON? String? Number? Boolean? You can’t decide it just based on the XML instance You have to know the schema 25
  • 26. Jsonix is type-safe Jsonix knows types of elements and attributes from the mapping … and converts strings from/to these types automatically Jsonix always produces values in JSON and XML according to the types defined in the mapping 26
  • 27. Jsonix converts the types automatically <WMS_Capabilities … version="1.3.0" updateSequence="163"> <Service> … </Service> <Capability> <Request> … </Request> <Exception> … </Exception> <Layer> … <Layer queryable="1"> … </Layer> </Layer> </Capability> </WMS_Capabilities> queryable is a boolean: { "queryable" : true, … } Because the mappings says so: 27
  • 28. Safe, automatic type conversion === less work 28
  • 29. Jsonix uses declarative mappings Jsonix mappings are just descriptions of structures, not imperative programs 29
  • 30. Mappings are essential for strong structures and safe typing 30
  • 31. Jsonix can generate mappings from XSDs Jsonix Runtime XSD Mapping Jsonix Schema Compiler {“JS”:”ON”} <x:ml/> 31
  • 32. ..as follows java -jar jsonix-schema-compiler.jar -catalog schemas/catalog.cat schemas/ogc/wms/1.3.0/capabilities_1_3_0.xsd -b schemas -d mappings Generates Jsonix mappings for WMS 1.3.0: WMS_1_3_0_Full.js GitHub: http://bit.do/jsonix-006 32
  • 33. Experimental: Generate JSON Schemas from XSDs Jsonix Runtime XSD Mapping Jsonix Schema Compiler {“JS”:”ON”} <x:ml/> 33 JSON Schema Experimental java -jar jsonix-schema-compiler.jar -generateJsonSchema …
  • 34. Experimental: Validate JSON against generated JSON Schemas Using the great “Another JSON Schema Validator” AJV // Load JSON Schemas var ajv = new Ajv(); ajv.addSchema(XMLSchemaJsonSchema, … ); ajv.addSchema(JsonixJsonSchema, … ); ajv.addSchema(XLink_1_0JsonSchema, 'http://www.w3.org/1999/xlink'); // Compile the validation function and validate var validate = ajv.compile(WMS_1_3_0JsonSchema); if (!validate(capabilitiesElement)) { console.log(validate.errors); } 34 [{ keyword: 'required', dataPath: '.value.capability.request.getCapabilities.dcpType['0'].http', message: 'property .http is required' }, … ]
  • 35. Compiling XSDs into mappings is hard 35 By Alex E. Proimos (http://www.flickr. com/photos/proimos/4199675334/) [CC BY 2.0 (http://creativecommons.org/licenses/by/2.0)], via Wikimedia Commons
  • 36. Compiling XSDs into mappings is hard We’ve huge number of schemas with complex interdependencies Schemas sometimes have errors We have to resolve naming collisions We’re often forced to customize generation or even patch schemas 36
  • 37. (Unofficial) OGC Schemas Project https://github.com/highsource/ogc-schemas Pre-generated mapping for OGC Schemas: JS↔XML: Jsonix mappings Java↔XML: JAXB classes Available via npmjs.org and Maven Central 37
  • 38. (Unofficial) OGC Schemas Project Compiles over 30 OGC Schemas with more than 80 single versions OWS, WMS, SLD, GML, Filter, WFS, WPS, WCS, WMC, SWE, SPS, SOS, OM, SensorML, KML, ISO 19139, CSW, and many more… … ready-to-use with Jsonix 38
  • 39. Using pre-generated mappings var mappings = [XLink_1_0, SMIL_2_0, SMIL_2_0_Language, GML_3_1_1, OWS_1_0_0, Filter_1_1_0, DC_1_1, DCT, CSW_2_0_2]; // Create a Jsonix context var context = new Jsonix.Context(mappings, { namespacePrefixes: { "http://www.opengis.net/cat/csw/2.0.2": "csw", "http://www.opengis.net/ogc": "ogc", "http://www.opengis.net/gml": "gml" } }); JSFiddle: http://bit.do/jsonix-007 39
  • 40. Takeaway Jsonix is a powerful Open-Source JavaScript library for XML↔JS conversion Works in browsers as well as Node.js Bidirectional, strongly-structured and type-safe Uses declarative XML↔JS mappings Mappings can be generated from XML Schemas The (unofficial) OGC Schemas Project provides ready-to-use pre-generated mapping for many OGC Schemas 40
  • 41. Jsonix can drastically simplify XML processing in JavaScript apps and thus save a lot of development effort https://github.com/highsource/jsonix 41