Jsonix Example - Parsing WMS GetCapabilities Response
HTML
<script src="https://cdn.rawgit.com/highsource/jsonix/master/dist/Jsonix-all.js"></script>
<script src="https://cdn.rawgit.com/highsource/w3c-schemas/master/scripts/lib/XLink_1_0.js"></script>
<script src="https://cdn.rawgit.com/highsource/ogc-schemas/master/scripts/lib/WMS_1_3_0.js"></script>
<h1>Jsonix Example - Parsing WMS GetCapabilities Response</h1>
<p>Original <a href="http://80.88.161.52/geoserver/SW14815563/wms?&SERVICE=WMS&REQUEST=GetCapabilities">XML</a>.</p>
<p>Parsed in JSON form:</p>
<pre id="json"></pre>
<p>Marshalled as XML:</p>
<pre id="xml"></pre>
JavaScript
// Original URL: http://demo.opengeo.org/geoserver/osm/wms?service=WMS&request=GetCapabilities
var getCapabilitiesUrl = "http://80.88.161.52/geoserver/SW14815563/wms?&SERVICE=WMS&REQUEST=GetCapabilities";
// Create a Jsonix context
var context = new Jsonix.Context([XLink_1_0, WMS_1_3_0],
{
namespacePrefixes : {
"http://www.opengis.net/wms" : "",
"http://www.w3.org/1999/xlink" : "xlink"
},
mappingStyle : "simplified"
});
// Create an unmarshaller (parser)
var unmarshaller = context.createUnmarshaller();
// Unmarshal from URL
unmarshaller.unmarshalURL(getCapabilitiesUrl, function(result) {
// Display the results
$('#json').html(JSON.stringify(result, null, 2));
var marshaller = context.createMarshaller();
$('#xml').text(marshaller.marshalString(result));
});