• Stars
    star
    150
  • Rank 245,731 (Top 5 %)
  • Language
    Prolog
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Translate XML Schema into equivalent JSON Schema

xsd2json

Translate an XML Schema into equivalent JSON Schema based on SWI-Prolog and Constraint Handling Rules (CHR). For usage directly in Prolog or node.js.

Installation

First, make sure SWI-Prolog is installed. This module expects the swipl binary to be in PATH somewhere. In other words, type this:

swipl

If that works, so will xsd2json.

Using npm, you can install xsd2json by calling this:

npm install -g xsd2json

Or simply clone this repository and manually run the preinstall scripts to create pre-compiled Prolog files:

git clone https://github.com/fnogatz/xsd2json.git
npm run preinstall

Usage as CLI

If you install xsd2json via npm it will create a new command xsd2json:

xsd2json /path/to/your.xsd > /created/schema.json

Usage with node.js

The xsd2json module can be used programmatically as function or stream:

var xsd2json = require('xsd2json');
var filename = 'test.xsd';

// use as stream: Read from stdin
xsd2json(filename)
  .pipe(process.stdout);

// use as function
xsd2json(filename, function(err, schemaObject) {
  console.log(JSON.stringify(schemaObject, null, 2));
});

In addition to the command line options provided by the Prolog module, there are the following options available in the node.js module:

  • noExe: true | false (default): Use the native Prolog interface instead of the pre-compiled cli.exe. This might be useful for MacOS users (see issue #87 for more details).
  • swi: 'swipl' (default): Executable to call SWI-Prolog.

Usage with Prolog

xsd2json provides a predicate xsd2json(+XSD,-JSON), which holds for a given XML Schema (either file path, URL or stream). For instructions on how to use xsd2json programmatically in Prolog, have a look at the Prolog module's Readme.

Background

This tool has been developed as part of my Bachelor's Thesis at University of Ulm, Germany. The thesis (PDF) explains the general idea of the translation process via Prolog and Constraint Handling Rules (CHR). It also contains tabular and graphical representations of the implemented translations of XML Schema fragments. A shorter explanation of the translation process can be found in the CHR Workshop paper "From XML Schema to JSON Schema: Translation with CHR".

Project Structure

xsd2json is developed in a test-driven way. This reflects in the project's folder structure, too: The /lib-pl directory contains the Prolog and CHR stuff while you will find the TAP testing framework implemented in node.js under /test. Both directories contain their own Readme-File that explain their usage.

Known Bugs

xsd2json's tests are always executed using the latest stable release of SWI-Prolog. Make sure to have the latest version installed before you file a bug.

Apparently SWI-Prolog of version 7.2.x ships with a bug in the CHR implementation. Use version 7.4 or higher instead.

Alternatives

More Repositories

1

clocker

Command-line tool to track project hours
JavaScript
420
star
2

CHR.js

Compile and run Constraint Handling Rules (CHR) in JavaScript
JavaScript
103
star
3

magento2-matomo

Matomo Analytics Module for Magento 2
PHP
50
star
4

swivm

SWI-Prolog Version Manager - Bash script to manage multiple active SWI-Prolog versions
Shell
41
star
5

dgtchess

An event-driven JavaScript connector for electronic DGT chess boards
JavaScript
23
star
6

geospatial-demo

Example location-based app to demonstrate the power of MongoDB, node.js and Websockets
JavaScript
17
star
7

transportation

node.js module to display and manipulate public transport data
JavaScript
16
star
8

plammar

A Prolog grammar written in Prolog, for parsing and serialising Prolog code.
Prolog
12
star
9

tap

Write TAP tests with SWI-Prolog
Prolog
12
star
10

dcg4pt

Extend Definite Clause Grammars for Prolog by the corresponding parse tree
Prolog
9
star
11

feedback-to-gitlab

Server to generate GitLab issues for user feedback
JavaScript
9
star
12

timetraveller

Webservice to explore spatio-temporal data in an interactive way.
JavaScript
7
star
13

talks

A little collection of talks I gave
JavaScript
7
star
14

CHR.js-website

The code that runs http://chrjs.net
JavaScript
7
star
15

date_time

Logical arithmetic on dates and times in Prolog
Prolog
6
star
16

race

Prolog client for the SOAP interface of the Attempto Reasoner RACE
Prolog
6
star
17

CHR-Constraint-Server

A Persistent CHR Webserver
Prolog
5
star
18

CHR-Minesweeper

Simple Minesweeper application with Prolog and Constraint Handling Rules (CHR)
Prolog
5
star
19

CHR-Linear-Equation-Solver

Linear Equation Solving using Constraint Handling Rules
Prolog
4
star
20

cli_table

Pretty unicode tables for the CLI with Prolog
Prolog
4
star
21

RKI-Data-Diff-lfs

Shell scripts to get a minimal set of SQL commands for persistent yet efficient storage of RKI data for COVID19
Shell
4
star
22

Thesis-Makefile

Curated Makefile with best practices, conventions, and tips for writing LaTeX theses.
Makefile
3
star
23

CHR-Benchmarks

Compare the execution runtimes of different implementations of Constraint Handling Rules (CHR)
C
3
star
24

babel-plugin-chr

Babel plugin that precompiles CHR.js source code
JavaScript
3
star
25

CTX

Chess Tournament Exchange Format
Shell
3
star
26

tablediff

Shell scripts to get a minimal set of SQL commands for table synchronisation.
Shell
2
star
27

alexa.pl

Alexa skill development with SWI-Prolog
Prolog
2
star
28

chess.json

JSON Schema for saving Chess Tournaments
JavaScript
2
star
29

xsd

Prolog
2
star
30

CHR-Constraint-Store

Incremental constraint store for Prolog's Constraint Handling Rules (CHR) module.
Prolog
1
star
31

zeitpunkt

Tools to work with GeoJSON LineStrings with given time components
JavaScript
1
star
32

fnogatz.github.io

Personal Website of Falco Nogatz
JavaScript
1
star
33

cli-cal

[DEPRECATED] Github-like calendar graph for the command line
JavaScript
1
star
34

tconsole

Render objects in the console
JavaScript
1
star
35

swtparser.js

Parse SWT Swiss-Chess Tournament files with JavaScript
JavaScript
1
star
36

SWT-structure-files

Structure files for SWT Swiss Chess Tournament files
1
star
37

quickchess

OCR for chess game notations
TypeScript
1
star
38

uniwue-lernplaetze-scraper

Save the occupancy rates of working spaces in the libraries of the University of WΓΌrzburg, Germany.
JavaScript
1
star