xsd4js

1.0.2 • Public • Published

xsd4js

About

Converts XSD schemas in ES6 classes with nested parsing architecture.

Example:

XSD Schema:

<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema elementFormDefault="qualified"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <!-- ... -->
    <xsd:complexType name="bookType">
        <xsd:sequence>
            <xsd:element name="title" type="xsd:string" />
            <xsd:element name="author" type="authorName" />
            <xsd:element name="genre" type="xsd:string" minOccurs="0" />
        </xsd:sequence>
        <xsd:attribute name="price" type="xsd:decimal" use="required" />
        <xsd:attribute name="publicationdate" type="xsd:date" />
        <xsd:attribute name="ISBN" type="xsd:string" />
    </xsd:complexType>
    <!-- ... -->
</xsd:schema>

Generated EC6 class:

import AuthorName from './AuthorName';

export default class BookType {
    constructor(data) {
        if (!data) return;

        this.author = data.author ? new AuthorName(data.author) : null;
        this.genre = data.genre; // string
        this.iSBN = data.ISBN; // string
        this.price = data.price;
        this.publicationdate = data.publicationdate;
        this.title = data.title; // string
    }

    toString() {
        return JSON.stringify(this, null, 4);
    }
}

Check the folder ./.examples/ in order to have a better overview of the parser capabilities as:

  • ENUM
  • Array
  • Regular expression
  • Limit length
  • More...

Install

Run npm install xsd4js.

Usage

You must define the output folder and the XSD file or folder:

xsd4js <outuput_folder> <xsd_file/folder_path>

Example:

File: xsd4js ./.examples/bin ./.examples/example.xsd

Folder: xsd4js ./.examples/bin ./.examples/

Contributing

If you run into any problems or errors, report them here.

If you want to add something to the project, create a pull request here.

Readme

Keywords

none

Package Sidebar

Install

npm i xsd4js

Weekly Downloads

2

Version

1.0.2

License

MIT

Last publish

Collaborators

  • happycargmbh