I want to build a coding of data converter that convert XML to JSON dealing with weather files. Those weather files have multiple ‘include’ and ‘import’ and ‘schemas’.
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns:iwxxm="http://icao.int/iwxxm/3.0" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:aixm="http://www.aixm.aero/schema/5.1.1" xmlns="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://icao.int/iwxxm/3.0" version="3.0.0">
<include schemaLocation="./common.xsd"/>
<import namespace="http://www.aixm.aero/schema/5.1.1" schemaLocation="http://www.aixm.aero/schema/5.1.1_profiles/AIXM_WX/5.1.1b/AIXM_Features.xsd"/>
<import namespace="http://www.opengis.net/gml/3.2" schemaLocation="http://schemas.opengis.net/gml/3.2.1/gml.xsd"/>
This is one example of my xsd files. As you can see there, it has include for schema location and several imports.
For the converter language, I am trying to use javascript or typescript.
I want to use xml4js library for this project.
I want to ask some advices how to define fetching multiple schemas/import or include.
For reference, this is my converter code:
var fs = require('fs');
var util = require('util');
var xml4js = require('xml4js');
// Most of xml2js options should still work
var options = {};
var parser = new xml4js.Parser(options);
// Default is not to download schemas automatically, so we should add it manually
var xsd = fs.readFileSync('./tests/xsd/IWXXM/airmet.xsd', {encoding: 'utf-8'});
var xml = fs.readFileSync('./tests/xml/IWXXM/airmet-A6-1a-TS.xml', {encoding: 'utf-8'});
parser.addSchema('http://icao.int/iwxxm/3.0', xsd, function (err, importsAndIncludes) {
// importsAndIncludes contains schemas to be added as well to satisfy all imports and includes found in xsd file
parser.parseString(xml, function (err, result) {
console.log(util.inspect(result, false, null));
});
});
I want to solve that importsandincludes coding part, but i feel lost somehow.
I am not sure this is the right way to ask the question here…:( I am newbie for Stackoverflow. So if you need more resources or information please let me know!