Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
XML to JSON Conversion Issue - defining multiple schemas

I want to build a data converter for XML to JSON, dealing with weather files. Those weather files have multiple 'include' and 'import' and 'schemas', and I want to know how to deal with these using xml4js, or some other javascript library.

This is one example of my xsd files. As you can see there, it has include for schema location and several imports:

<?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"/>

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!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!