Giter Club home page Giter Club logo

xsd2json's Introduction

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

xsd2json's People

Contributors

dependabot[bot] avatar fnogatz avatar greenkeeper[bot] avatar greenkeeperio-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xsd2json's Issues

XSD Cycles not taken in charge by XSD2JSON

Hello,

I'm working as a Technical Architecte on SOA Governance standards.
My current client designed an Enterprise Data model with XSD files, some of objects are referencing themselves (a company has contacts, and contacts are attached to a company).
Today, I'm working on JSon Technical Design rules, and I wanted to base my assessment on Json Enterprise Data model, but the cycles between XSD are not correctly understood by xsd2json.

I also had some issues when I am not using the option "-u", I'm quite sure that using this option by default could help many people who are trying to resolve the problem by installing Visual Studio or Microsoft Visual Express or SDK or many other frameworks ..... With -u option at the end it is not necessary and more simple.

Could you please provide a patch for these loops?
From my point of view, I analyzed the JSON files generated from an XSD without cycles, and I can see that references on complextypes are writen, as for XSD. So when the Complextype is detected the first time, it must be generated in the JSON file, but the second time, it is not necessary to go ahead on it.
I think that a simple hashtable in memory, reminding the complextype "already processed" in order to NOT analyze them twice could be a good entry point, but as I am not expert on Javascript and Swiple programs, I am not able to propose a solution.

You can contact me on this email: [email protected]

Thxs for your help,
Richard

Keep getting error running example from doc

Used xsd:

<?xml version="1.0" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="dog" type="xs:string" />
</xs:schema>

code:

let xsd2json = require('xsd2json');
let filename = '${__dirname}/schema.xsd';

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

Error message:

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at /home/heucles/dev/c4-omnigateway/app/node_modules/xsd2json/index.js:55:25
    at ConcatStream.<anonymous> (/home/heucles/dev/c4-omnigateway/app/node_modules/concat-stream/index.js:36:43)
    at emitNone (events.js:110:20)
    at ConcatStream.emit (events.js:207:7)
    at finishMaybe (/home/heucles/dev/c4-omnigateway/app/node_modules/readable-stream/lib/_stream_writable.js:607:14)
    at endWritable (/home/heucles/dev/c4-omnigateway/app/node_modules/readable-stream/lib/_stream_writable.js:615:3)
    at ConcatStream.Writable.end (/home/heucles/dev/c4-omnigateway/app/node_modules/readable-stream/lib/_stream_writable.js:571:41)
    at Socket.onend (_stream_readable.js:598:10)
    at Object.onceWrapper (events.js:314:30)
undefined
<Buffer 5b 46 41 54 41 4c 20 45 52 52 4f 52 3a 0a 09 43 6f 75 6c 64 20 6e 6f 74 20 6f 70 65 6e 20 72 65 73 6f 75 72 63 65 20 64 61 74 61 62 61 73 65 20 22 2f ... >

An in-range update of tap is breaking the build 🚨

Version 10.4.0 of tap just got published.

Branch Build failing 🚨
Dependency tap
Current Version 10.3.4
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As tap is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 7 commits.

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Root element not correct translated

The following example XSD does not create any JSON Schema:

<?xml version="1.0" ?>
<xs:schema>
  <xs:element name="pet">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:enumeration value="dog" />
        <xs:enumeration value="cat" />
      </xs:restriction>
    </xs:simpleType>
  </xs:element>
</xs:schema>

xs:choice and xs:sequence ignored in properties

The following schema element

<xs:complexType name="Resource">
  <xs:annotation><xs:documentation>
     Added in Version 1.2: INFO for diagnostics in several places
  </xs:documentation></xs:annotation>
  <xs:sequence>
    <xs:element name="DESCRIPTION" type="anyTEXT" minOccurs="0"/>
    <xs:element name="INFO" type="Info" minOccurs="0" maxOccurs="unbounded"/>
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="COOSYS" type="CoordinateSystem"/><!-- Deprecated in V1.2 -->
      <xs:element name="GROUP" type="Group" />
      <xs:element name="PARAM" type="Param" />
    </xs:choice>
</xs:complexType>

gives this JSON schema fragment:

   "Resource": {
      "properties": {
        "name": {
          "type": "string"
        },
        "DESCRIPTION": {
          "$ref": "#/definitions/anyTEXT"
        },
        "INFO": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/Info"
          },
          "minItems": 0
        }
}

We can see that children elements COOSYS/GROUP/PARAM are ignored. Therefore they are not validated although their schema is well defined in the schema.

SyntaxError: Unexpected end of JSON input

Operating System = Windows 10
Node 6.10

var path = require('path');
var xsd2json = require('xsd2json');

var filename = path.join(__dirname, 'node_modules/xsd2json/test/XMLSchema2.xsd');

// use as function
xsd2json(filename, function(err, schemaObject) {
	if (err) console.log(err);
	console.log(JSON.stringify(schemaObject, null, 2));
});
[1] SyntaxError: Unexpected end of JSON input
[1]     at Object.parse (native)
[1]     at C:\@repositories\pir-model-preparer\node_modules\xsd2json\index.js:55:25
[1]     at ConcatStream.<anonymous> (C:\@repositories\pir-model-preparer\node_modules\concat-stream\index.js:36:43)
[1]     at emitNone (events.js:91:20)
[1]     at ConcatStream.emit (events.js:185:7)
[1]     at finishMaybe (C:\@repositories\pir-model-preparer\node_modules\readable-stream\lib\_stream_writable.js:504:14)
[1]     at endWritable (C:\@repositories\pir-model-preparer\node_modules\readable-stream\lib\_stream_writable.js:514:3)
[1]     at ConcatStream.Writable.end (C:\@repositories\pir-model-preparer\node_modules\readable-stream\lib\_stream_writable.js:484:41)
[1]     at Socket.onend (_stream_readable.js:511:10)
[1]     at Socket.g (events.js:291:16)

UnsignedInt, hexBinary and Co.

Hey guy,

at first thanks for working on my issue. Nevertheless I have the question, if you could add support for xs:unsignedInt.

Would it be possible, to add the entry type to every json-object, nevertheless if you can resolve the type?
Example:
If the type is xs:unsignedInt and you are not able to resolve it, you can just add
"element" : {
"type" :"unsignedInt",
"description" :"whatever"
}

Maybe you already added this support, but atm I am at version 1.0.1 because with version 1.2.1 the generation of json-schema-files is not working anymore. Is there a way for me, to debug the process or to help finding the error on my xsd-files or your process?

Atm you dont create an entry for the type-field instead, right?

Thanks in advance,
PiQ99

Order gets changed while transforming

Hey guy,

is there any hint, why the order gets changed for xsd-elements, that are getting transformed into a json-schema file?

I came across this problem, when the order was checked of the elements that are included in a sequence-tag. There, the order is not allowed to be changed related to the xsd-schema. In contrast to this, I know, json is not able / or dont has to maintain the same order.

Here is an example, which was converted with version 1.0.1 of xsd2json: http://jsfiddle.net/PiQ99/vz3mcm7g/

Is there anything that can be changed to have the same order? :-)

Thanks for your answer.

Validation after conversion

Hi,

I need to do xml validation against xsd. i thought of using libxmljs module. i couldn't move forward with it as it has some building/installation issues. Moreover, i haven't found any other module to accomplish the task.

Now, i would like to use xsd2json converter to convert XSD to JSON and XML to JSON and validate it.

Please let me know if there is already a validator for this. or how do you suggest me to go about this.

Thanks,
Raja

Command line argument

swipl --quiet --nodebug --g 'main,halt' -s cli.pl -- < /path/to/your.xsd

--g 'main,halt' should be -g 'main,halt'

Domain error: `sgml_option' expected, found `help(false)'

Ubuntu 16.04
swi-prolog-nox 6.6.4-2ubuntu1
xsd2json 1.7.7

$ xsd2json schema.xsd > schema.json
ERROR: Prolog initialisation failed:
ERROR: Domain error: `sgml_option' expected, found `help(false)'

I have no knowledge of prolog whatsoever, but I am a developer. I can hack and slash my way through code if need be. What other information do you need?

xsd2json error

xsd2json
/usr/local/bin/xsd2json: 3: exec: /home/fnogatz/.swivm/versions/7.2.3/lib/swipl-7.2.3/bin/x86_64-linux/swipl: not found

What is "/home/fnogatz/.swivm/versions/7.2.3/lib/swipl-7.2.3/bin/x86_64-linux/swipl" ?

An in-range update of commander is breaking the build 🚨

Version 2.12.1 of commander was just published.

Branch Build failing 🚨
Dependency commander
Current Version 2.12.0
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

commander is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes v2.12.1
  • Move @types/node to dev dependency
Commits

The new version differs by 4 commits.

  • 91c2514 Merge pull request #721 from abetomo/version_bump_2.12.1
  • 0a91554 version bump 2.12.1
  • a7124fc Merge pull request #718 from chengkungui/patch-1
  • 245584e Move @types/node to dev dependency

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Problem with xhtml tag in a annotation element

The XMLSchema.xsd authorizes any element (with relaxed validation) in documentation content :

<xs:element name="documentation" id="documentation">
...
  <xs:complexType mixed="true">
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
      <xs:any processContents="lax"/>
    </xs:sequence>
    ...
  </xs:complexType>
</xs:element>

so this xsd

<?xml version="1.0" encoding="UTF-8"?>
<s:schema targetNamespace="http://www.mgdis.fr/public/demande-paiement/v1" 
    xmlns:s="http://www.w3.org/2001/XMLSchema" 
    xmlns:tns="http://www.mgdis.fr/public/demande-paiement/v1" 
    elementFormDefault="qualified">
  <s:element name="acomplexobject">
    <s:complexType>
      <s:sequence>
        <s:element name="aproperty" type="s:string" minOccurs="0">
          <s:annotation>
            <s:documentation xml:lang="EN"><p>A description</p></s:documentation>
          </s:annotation>
        </s:element>
      </s:sequence>
    </s:complexType>
  </s:element>
</s:schema> 

should generate this jsonschema

{
  "type":"object", 
  "properties": {
    "aproperty": {
      "description":"<p>A description</p>",
      "type":"string"
    }
  }
}

but it fails with :

ERROR: Prolog initialisation failed:
ERROR: term_to_atom/2: Type error: `text' expected, found `http://www.w3.org/2001/XMLSchema:documentation'

The question is open :
Does it parse the xhtml tag (especially <br/> with \n) or does it restitute the description unchanged ?

P.S. : Thanks for your projet :)

npm install fails on Ubuntu

Hi

I do not manage to install xsd2json with .
swipl has ben installed from sources and sems to to work.
I got the following errors which are opaque to me.
That look like a broken dependency.
Have you an idea?

Laurent

michel@obs-he-lm:~/gitRepositories/xsd2json$ sudo npm install -g xsd2json
/usr/bin/xsd2json -> /usr/lib/node_modules/xsd2json/lib-pl/cli

> [email protected] postinstall /usr/lib/node_modules/xsd2json
> npm run create-qlf


> [email protected] create-qlf /usr/lib/node_modules/xsd2json
> swipl -O --goal=main -o lib-pl/cli -c lib-pl/cli.pl

ERROR: /usr/lib/node_modules/xsd2json/lib-pl/helpers.pl:8:
	source_sink `library(sgml_write)' does not exist
Warning: /usr/lib/node_modules/xsd2json/lib-pl/helpers.pl:8:
	Goal (directive) failed: helpers:use_module(library(sgml_write))
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:9:
	source_sink `library(chr)' does not exist
Warning: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:9:
	Goal (directive) failed: xsd2json:use_module(library(chr))
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:10:
	source_sink `library(http/http_open)' does not exist
Warning: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:10:
	Goal (directive) failed: xsd2json:use_module(library(http/http_open))
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:13:
	source_sink `library(sgml)' does not exist
Warning: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:13:
	Goal (directive) failed: xsd2json:use_module(library(sgml))
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:30:18: Syntax error: Operator expected
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:40:18: Syntax error: Operator expected
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:42:1: Syntax error: Operator expected
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:56:18: Syntax error: Operator expected
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:63:1: Syntax error: Operator expected
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:78:18: Syntax error: Operator expected
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:85:1: Syntax error: Operator expected
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:90:18: Syntax error: Operator expected
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:99:1: Syntax error: Operator expected
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:111:18: Syntax error: Operator expected
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:115:1: Syntax error: Operator expected
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:130:18: Syntax error: Operator expected
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:147:18: Syntax error: Operator expected
ERROR: /usr/lib/node_modules/xsd2json/lib-pl/xsd2json.pl:152:1: Syntax error: Operator expected
....

Json schema output have a '|:' string in the console

Why there is an extra |: string in the most begining of json schema output, my xml schema is:

<!-- filename: models.xsd-->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="models">
        <xs:complexType>
            <xs:all>
                <xs:element name="User" type="User" minOccurs="0"/>
                <xs:element name="Device" type="Device" minOccurs="0"/>
                <xs:element name="Ad" type="Ad" minOccurs="0"/>
            </xs:all>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="User">
        <xs:sequence>
            <xs:element name="id" type="xs:nonNegativeInteger"/>
            <xs:element name="name" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Device">
        <xs:sequence>
            <xs:element name="id" type="xs:nonNegativeInteger"/>
            <xs:element name="name" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Ad">
        <xs:sequence>
            <xs:element name="id" type="xs:nonNegativeInteger"/>
            <xs:element name="name" type="xs:string"/>
            <xs:element name="user_id" type="xs:nonNegativeInteger"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

and with the following command line:

swipl --quiet --nodebug -g 'main,halt' -s lib/cli.pl -- < test/xsd/models.xsd

The output is:

|:  {
  "definitions": {
    "User": {
      "required": ["id", "name" ],
      "type":"object",
      "properties": {
    "id": {"type":"integer", "minimum":0, "exclusiveMinimum":false},
    "name": {"type":"string"}
      }
    },
    "Device": {
      "required": ["id", "name" ],
      "type":"object",
      "properties": {
    "id": {"type":"integer", "minimum":0, "exclusiveMinimum":false},
    "name": {"type":"string"}
      }
    },
    "Ad": {
      "required": ["id", "name", "user_id" ],
      "type":"object",
      "properties": {
    "id": {"type":"integer", "minimum":0, "exclusiveMinimum":false},
    "name": {"type":"string"},
    "user_id": {"type":"integer", "minimum":0, "exclusiveMinimum":false}
      }
    }
  }
}

Missing JSON definition of complexType if does contain simpleContent

The complextType someType will not be added to the JSON definition output.
Looks like the simpleContent element is not recorginzed by the translator.

input

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns="http://example.local"
           xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://example.local"
           elementFormDefault="qualified">
    <xs:element name="test" type="someType" />

    <xs:complexType name="someType">
        <xs:simpleContent>
            <xs:extension base="someRestrictionType">
                <xs:attribute name="id" type="xs:ID" />
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:simpleType name="someRestrictionType">
        <xs:restriction base="xs:double">
            <xs:minInclusive value="0" />
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

output

{
  "definitions": {
    "someRestrictionType": {
      "type":"number",
      "minimum":0,
      "exclusiveMinimum":false
    }
  },
  "allOf": [
    {
      "$ref":"#/definitions/someType"
    }
  ]
}

Problem with elements named "description"

the xsd2jon command fails with this xsd :

<?xml version="1.0" encoding="UTF-8"?>
<s:schema targetNamespace="http://www.mgdis.fr/public/demande-paiement/v1" 
    xmlns:s="http://www.w3.org/2001/XMLSchema" 
    xmlns:tns="http://www.mgdis.fr/public/demande-paiement/v1" 
    elementFormDefault="qualified">
  <s:element name="acomplexobject">
    <s:complexType>
      <s:sequence>
        <s:element name="aproperty" type="s:string" minOccurs="0"/>
        <s:element name="description" type="s:string" minOccurs="0">
          <s:annotation>
            <s:documentation xml:lang="EN">A description for the description field</s:documentation>
          </s:annotation>
        </s:element>
      </s:sequence>
    </s:complexType>
   </s:sequence>
</s:schema> 

This should generate a json like :

{
  "type":"object",
  "properties": {
    "description": {
      "description":"A description for the description field",
      "type":"string"
    },
    "aproperty": {"type":"string"}
  }
}

but the process returns this error :

ERROR: Prolog initialisation failed:
ERROR: string_concat/3: Type error: `atomic' expected, found `json([description=A description for the description field,type=string])'

Syntax errors

Hello again :)

When running cli.pl I encounter the following errors:

ERROR: c:/users/mouton-a/sandbox/git/xsd2json/prolog-xsd2json/merge_json.pl:60:14: Syntax error: Operator expected
ERROR: c:/users/mouton-a/sandbox/git/xsd2json/prolog-xsd2json/xsd2json.pl:380:12: Syntax error: Operator expected
ERROR: c:/users/mouton-a/sandbox/git/xsd2json/prolog-xsd2json/xsd2json.pl:381:11: Syntax error: Operator expected

Most of the times this is non-blocking. But on some XSDs it is followed by the blocking error:

ERROR: c:/users/mouton-a/sandbox/git/xsd2json/prolog-xsd2json/cli.pl:5: Initialization goal raised exception:
ERROR: xsd2json:convert_xsd_restriction/3: Undefined procedure: xsd2json:json_false/1

The 3 lines contain arobases. Coincidence ? I think not !

Wondering if this could be an encoding problem I tried adding ':- encoding(utf8).' to the source files. But it didn't fix anything and being totally ignorant of prolog I am already out of ideas.

Environment:

$ swipl -v
SWI-Prolog version 6.6.6 for i386-win32

Error when attempting to use xsd2json

Attempting to convert 5 XSDs linked by import using this tool and unfortunately it gets so far then stops with the following error: (I have installed swipl)

debug: Spawn prolog xsd2json program
events.js:182
throw er; // Unhandled 'error' event
^

Error: spawn swipl ENOENT
at _errnoException (util.js:1019:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
at onErrorNT (internal/child_process.js:374:16)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)

unfortunately, i'm unable to provide the XSDs. Is there any other information I can provide to assist?

Error installing on Ubuntu via npm

When I tried to run on Ubuntu 14.04 this happen:

/usr/local/bin/xsd2json -> /usr/local/lib/node_modules/xsd2json/lib-pl/cli

[email protected] postinstall /usr/local/lib/node_modules/xsd2json
npm run create-qlf

/usr/local/lib/node_modules/.bin/npm: 2: exec: /usr/local/lib/node_modules/.bin/node: not found
npm ERR! Linux 3.13.0-92-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "xsd2json"
npm ERR! node v4.2.2
npm ERR! npm v2.14.7
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn

npm ERR! [email protected] postinstall: npm run create-qlf
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the [email protected] postinstall script 'npm run create-qlf'.
npm ERR! This is most likely a problem with the xsd2json package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! npm run create-qlf
npm ERR! You can get their info via:
npm ERR! npm owner ls xsd2json
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /home/sciensa/npm-debug.log

Doesnt seem to work..just sits idle

I installed the swipl on my mac osx 10.10 (Yosemite). I had to manually add a /usr/local/bin/swipl link. When I run swipl I get the prompt, so I exit out. I then installed xsd2json and that was fine. Now when I run xsd2json, I just see a spinning | character and it sits there forever. I've let it go for 2 hours, still nothing. I thought maybe it was just extremely slow, but obviously it's more than that.

Are there some updated Mac OS instructions/steps on how to install and get it to work? I can't seem to find the man documentation for it either.

Thanks.

Error for xsd to json

I get this error:

stack": [
"Error: spawn swipl ENOENT",
" at exports._errnoException (util.js:746:11)",
" at Process.ChildProcess._handle.onexit (child_process.js:1053:32)",
" at child_process.js:1144:20",
" at process._tickDomainCallback (node.js:381:11)",
" at process. (/home/syedn/proj/ori/propfi/node_modules/loopback/node_modules/continuation-local-storage/node_modules/async-listener/index.js:18:15)"
],
"level": "error",
"message": "uncaughtException: spawn swipl ENOENT"

issue with xsd referencing

Hi,

This is a great tool.
I'm facing issue in the following scenario.
XSD1.....>XSD2------>XSD3.
It's throwing out error (going to infinite loop)while trying to reference xsd3.
Is there a setting that restricting to do get 3rd level reference?
Thanks,
Purush

An in-range update of commander is breaking the build 🚨

The devDependency commander was updated from 2.19.0 to 2.20.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

commander is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v2.20.0
  • fix: resolve symbolic links completely when hunting for subcommands (#935)
  • Update index.d.ts (#930)
  • Update Readme.md (#924)
  • Remove --save option as it isn't required anymore (#918)
  • Add link to the license file (#900)
  • Added example of receiving args from options (#858)
  • Added missing semicolon (#882)
  • Add extension to .eslintrc (#876)
Commits

The new version differs by 18 commits.

  • 3e8bf54 Merge pull request #946 from abetomo/version_bump_2.20.0
  • 1ffcbef version bump 2.20.0
  • 50922d8 Merge pull request #935 from MarshallOfSound/fix-deep-sym-link-resolution
  • 994d24d fix: resolve symbol links until their are no more symbolic links
  • 291fc04 Merge pull request #930 from kira1928/update-index.d.ts
  • a469137 some more fix.
  • a679949 Refine variable name. Use strict type definition instead of
  • e31bb8a Update index.d.ts
  • 4542306 Merge pull request #924 from ForJing/patch-1
  • 77bb580 Update Readme.md
  • 68545af Remove --save option as it isn't required anymore
  • 82d0d0a fix url :construction:
  • cec57f5 Add link to the license file :+1:
  • d240081 Update Readme.md
  • 03f7d38 Added example of receiving args from options

There are 18 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of tap is breaking the build 🚨

The devDependency tap was updated from 12.5.1 to 12.5.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

tap is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Commits

The new version differs by 10 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of tap is breaking the build 🚨

Version 11.1.1 of tap was just published.

Branch Build failing 🚨
Dependency tap
Current Version 11.1.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

tap is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 4 commits.

  • 95faf6c 11.1.1
  • 283c8e6 Handle EPIPE better in exceptional edge cases
  • b727234 Fix obscure edge case when this.results is not set
  • 13073a7 docs: correct 100 PR link

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

error on: npm install -g xsd2json

npm install -g xsd2json
npm ERR! Darwin 15.3.0
npm ERR! argv "/Users/gabrielmancini/.nvm/versions/node/v0.12.4/bin/node" "/Users/gabrielmancini/.nvm/versions/node/v0.12.4/bin/npm" "install" "-g" "xsd2json"
npm ERR! node v0.12.4
npm ERR! npm  v2.10.1
npm ERR! path /Users/gabrielmancini/.nvm/versions/node/v0.12.4/lib/node_modules/xsd2json/lib-pl/cli
npm ERR! code ENOENT
npm ERR! errno -2

npm ERR! enoent ENOENT, chmod '/Users/gabrielmancini/.nvm/versions/node/v0.12.4/lib/node_modules/xsd2json/lib-pl/cli'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/gabrielmancini/Developer/Watson/jsonMass/schema/npm-debug.log

stack_limit

Hello,
Having issues with increasing the stack limit on my mac.

:/~/Downloads/xsd2json-master $ swipl --stack_limit=4g
Welcome to SWI-Prolog (threaded, 64 bits, version 8.0.2)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit http://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

?- halt.

Post this setting of stack_limit to 4 GB I run the conversion program but fails with below error:

ERROR: -g user:main: Stack limit (1.0Gb) exceeded
ERROR: Stack sizes: local: 3.4Mb, global: 0.6Gb, trail: 0.4Mb
ERROR: Stack depth: 77,673,357, last-call: 100%, Choice points: 8,947
ERROR: In:
ERROR: [77,673,357] assoc:adjust(yes, '<garbage_collected>', left, _27862, yes)
ERROR: [77,673,354] assoc:insert(<, '<garbage_collected>', '<garbage_collected>', x, _27890, _27892)
ERROR: [77,673,352] assoc:insert(<, '<garbage_collected>', '<garbage_collected>', x, _27918, _27920)
ERROR: [77,673,350] assoc:insert(<, '<garbage_collected>', '<garbage_collected>', x, _27946, _27948)
ERROR: [77,673,348] assoc:insert(<, '<garbage_collected>', '<garbage_collected>', x, _27974, _27976)
ERROR:
ERROR: Use the --stack_limit=size[KMG] command line option or
ERROR: ?- set_prolog_flag(stack_limit, 2_147_483_648). to double the limit.

It's clearly seen that the 4GB value is not applied.

Can you please help?

Support of xs:extension and xs:include

Thanks for the impressive piece of work.

In your thesis you specifically mention that xsd2json doesn't support the extension of complex types. Do you have any project to fill this gap ? If not, do you have a solution in mind to implement this functionality that maybe another developer could contribute ?

I have no deep understanding of the problem or of your program, but I wonder if the simplest solution could be to do some merging of the complex types definitions before applying CHR rules ?

I also wonder about include and import that you say are not supported. Do you think a simple merge of included schemas in the root schema will do the trick ?

Basically: do you think a not too complex tranformation (xslt or other) applied on the schemas before processing by xsd2json could help overcome its limitations ?

Alban

ref, complexType in element-tag, documentation in non-leaf-tags

Hey,

at first I have to say, I like your work. It is a great tool that helps me a lot at the moment. In addition I wanted to ask, if you plan further development? There are several things to do I guess.
Of course I saw, you did not commit anything about two months now, but maybe you continued developing at home?

e.g. what about:

  • ref-attributes in element-tags
  • the documentation-attibute in a complexType (it gets ignored I guess atm?)
  • complexTypes in element-tags?

These are several things that do not work atm, afaik, and I wanted to ask, if you are going to fix these things, maybe?

Thanks for your answer and have a nice week!

An in-range update of commander is breaking the build 🚨

Version 2.13.0 of commander was just published.

Branch Build failing 🚨
Dependency commander
Current Version 2.12.2
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

commander is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes v2.13.0
  • Do not print default for --no-
  • remove trailing spaces in command help
  • Update CI's Node.js to LTS and latest version
  • typedefs: Command and Option types added to commander namespace
Commits

The new version differs by 8 commits.

  • 291fbaa Merge pull request #748 from abetomo/version_bump_2.13.0
  • 63f1ee9 version bump 2.13.0
  • f13ee18 Do not print default for --no-
  • ff712f1 remove trailing spaces in command help
  • fefda77 Merge pull request #713 from sveinburne/feature/enhanced-typedefs
  • d812171 Merge pull request #723 from abetomo/add_nodejs_version_to_ci_yml
  • 498ce71 Update CI's Node.js to LTS and latest version
  • 965188f typedefs: Command and Option types added to commander namespace

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Not installed correctly on Windows

The xsd2json command is not installed correctly on Windows. It assumes the presence of /bin/sh.exe or /bin/sh, which (ha ha) does not exist on Windows unless you have Cygwin or similar.

At the very least, the documentation should be updated to reflect that. Ideally, unless a UNIX shell is required, the install should only reference Windows standard executable.

Referenced xsd files to be on corresponding jsonschema files

Thanks for this great tool.

Given a root xsd, is it possible to create separate corresponding jsonschema files for each xsds referenced along the way?

I have a large tree of xsds and swipl bails out with following error:
ERROR: -g main: Out of global stack

Any ideas welcome.

Fix for SWI 6: read_string/3 undefined

The read_string/3 predicate used in markup_to_string/4 of helpers.pl is defined only since SWI-Prolog of version 6 (corresponding commit). That's why xsd2json fails for XSDs which include xs:documentation tags:

> ./lib-pl/cli test/xsd/annotation.xsd 
ERROR: Prolog initialisation failed:
ERROR: helpers:markup_to_string/4: Undefined procedure: helpers:read_string/3

Options for xsd2json?

Is there the possibility, to add option-parameters to xsd2json :-)? E.g. it would be nice, if the user could handle, if the result file should contain "$ref"s or not?!

Thanks again!

ddex standard convertion not working

I try to convert with this code:

var xsd2json = require('xsd2json');
var filename = '../examples/release-notification.xsd';

// use as function
xsd2json(filename, {'debug-info':true},function(err, schemaObject) {
  if(err) throw err;
  console.log(JSON.stringify(schemaObject, null, 2));
});

the xml schema from here http://service.ddex.net/xml/ern/37/release-notification.xsd
but in the console just have this error
ERROR: -g user:main: false

what it means?

if I remove this , {'debug-info':true} from the function, the execution hangs

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Prolog initialisation failed

I'm sorry to reopen an issue which is rather likely a user support request (I'm an absolute beginner with Prolog). I guess that some other users can have to face the same problem.

I properly setup my swipl with Aptitude and swivm as suggested in thread #53

michel@obs-he-lm:~$ swipl --version
SWI-Prolog  version 7.2.3 for x86_64-linux
michel@obs-he-lm:~$ swipl
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.2.3)
Copyright (c) 1990-2015 ....
?- use_module(library(sgml)).
true.
?- use_module(library(chr)).
true.

When I try to process a schema, I get nothing on stdout; then I switch to the trace mode and I get the following output (truncated).

michel@obs-he-lm:~$ xsd2json -t purchaseorder.xsd
CHR:   (0) Insert: node_attribute(/home/michel/purchaseorder.xsd,[0],xmlns:xsd,http://www.w3.org/2001/XMLSchema,source) # <0>
....
....
CHR:   (1) Redo: node_attribute(/home/michel/purchaseorder.xsd,[0],xmlns:xsd,http://www.w3.org/2001/XMLSchema,source) # <0>
CHR:   (0) Fail: node_attribute(/home/michel/purchaseorder.xsd,[0],xmlns:xsd,http://www.w3.org/2001/XMLSchema,source) # <0>
ERROR: Prolog initialisation failed:
ERROR: Domain error: `chr_port' expected, found `none'

I've no idea at all (and Google either) about that chr_port.
Is there some missing parameter or resource?

LM

Only got empty object result

Hi there,
Thanks for this great library. I'm still cannot use this library properly.
I'm using windows 10, node v8.11.1, SWI-Prolog v7.6.4, and xsd2json v1.11.6 and I installed it globally.

Here is the simple xsd I've used

<?xml version="1.0" encoding="UTF-8"?>

<shiporder orderid="889923" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="shiporder.xsd">
  <orderperson>John Smith</orderperson>
  <shipto>
    <name>Ola Nordmann</name>
    <address>Langgt 23</address>
    <city>4000 Stavanger</city>
    <country>Norway</country>
  </shipto>
  <item>
    <title>Empire Burlesque</title>
    <note>Special Edition</note>
    <quantity>1</quantity>
    <price>10.90</price>
  </item>
  <item>
    <title>Hide your heart</title>
    <quantity>1</quantity>
    <price>9.90</price>
  </item>
</shiporder>

and then I've tried to run this on cmd xsd2json shiporder.xsd > schema.json and the result is schema.json file only contain

{
}

is there anything I've missed?
Thanks.

Unable to use either the cli or programatically on MacOS

I get the following error when I try to use xsd2json:

Could not open resource database "/usr/local/bin/xsd2json": Inappropriate ioctl for device]

I noticed that the /usr/local/bin/xsd2json is a symlink to .../lib-pl/cli.exe and also saw the commit that talked about windows compatibility. Could this be the issue?

An in-range update of tap is breaking the build 🚨

Version 10.7.0 of tap just got published.

Branch Build failing 🚨
Dependency tap
Current Version 10.6.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As tap is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 10 commits.

  • c417424 v10.7.0
  • 802cf70 update 'only' output test
  • dc67c58 add t.only()
  • 0f474d9 filter out --only and --grep skip messages
  • efd024d consolidate --only tests
  • f60b060 Further refining --only
  • 0d0ac05 runner test for --only
  • 7550694 update usage, add -O alias for --only
  • 8438249 add test for --only flag
  • 7e42a08 WIP TAP_ONLY, --only, {only: true} and warning to stderr if {only: true} but tap’s only option is not true

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

An in-range update of ajv is breaking the build 🚨

The devDependency ajv was updated from 6.8.1 to 6.9.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

ajv is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build could not complete due to an error (Details).

Release Notes for v6.9.0

OpenAPI keyword nullable can be any boolean (and not only true).
Custom keyword definition changes:

  • dependencies option in to require the presence of keywords in the same schema.
  • more strict validation of the definition using JSON Schema.
Commits

The new version differs by 14 commits.

  • cd404c4 6.9.0
  • 7079aed remove property in custom keyword definition schema
  • c89ca0e eslint option
  • 47c8fc9 refactor: use json schema to validate custom keyword definition
  • 33d1ac4 style fix
  • fdfbd44 feat: support for required dependencies of custom keyword (keywords that must be present in the same schema)
  • f080c91 docs: double quotes
  • 51e858e docs: clarify "format" option values
  • 0cf6e98 Merge branch 'mattpolzin-nullable-can-be-false'
  • ac2221a style fix
  • c5b9516 Merge branch 'master' into nullable-can-be-false
  • 58879a0 fix: pin jshint to 2.9.7 (#939)
  • 859259e Add tests that show that with nullable option on but 'nullable' keyword set to false an object is not nullable.
  • 28c85ad Allow nullable property of JSON Schema object to be false as well as true. Remove test that asserted failure if nullable was false.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

xmlns not used

The following XSD is perfectly valid:

<schema xmlns="http://www.w3.org/2001/XMLSchema">
  <element name="dog" type="string" />
</schema>

Unlike using the same with explicit xs: prefix namespace, it returns:

{
  "$ref":"#/definitions/string"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.