Parses WMS capabilities XML format to JSON. This is a simplified excerpt from OpenLayers code to be used separately from its large codebase.
npm install wms-capabilities --save
var WMSCapabilities = require('wms-capabilities');
...
new WMSCapabilities().parse(xmlString);
//or
new WMSCapabilities(xmlString).toJSON();
<script src="path/to/wms-capabilities.min.js"></script>
...
new WMSCapabilities().parse(xmlString);
Requires xmldom
to traverse XML
$npm install --save xmldom
then
var DOMParser = global.DOMParser = require('xmldom').DOMParser;
var WMSCapabilities = require('wms-capabilities');
...
new WMSCapabilities(xmlString).toJSON();
$ npm install -g wms-capabilities
$ cat capabilities.xml | wmscapabilities > out.json
$ # or
$ wmscapabilities capabilities.json > out.json