Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mbovel/relaxng-to-json-schema
https://github.com/mbovel/relaxng-to-json-schema
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/mbovel/relaxng-to-json-schema
- Owner: mbovel
- Created: 2020-01-28T15:09:45.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T19:37:29.000Z (about 2 years ago)
- Last Synced: 2024-10-28T21:25:50.714Z (3 months ago)
- Language: JavaScript
- Size: 272 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RelaxNG to Json Schema
This library contains functions to convert *simple* RelaxNG schemas to JSON Schemas and to convert between corresponding XML documents and JSON files.
The primary use-case is the generation of web UIs for XML data using existing libraries based on JSON schemas like [React Json Schema Form](https://github.com/rjsf-team/react-jsonschema-form) or [AutoUI](https://github.com/mbovel/autoui).
## Demonstration
A live playground can be found here: . It uses React Json Schema Form to display the UI.
## Usage
```html
import relaxngToJsonSchema from "../src/relaxngToJsonSchema.js";
import xmlToJson from "../src/xmlToJson.js";const rngSchema = parseXML(`
<element name="addressBook" xmlns="http://relaxng.org/ns/structure/1.0">
<zeroOrMore>
<element name="card">
<element name="name">
<text/>
</element>
<element name="email">
<text/>
</element>
</element>
</zeroOrMore>
</element>
`)const xmlContent = parseXML(`
<addressBook>
<card>
<name>John Smith</name>
<email>[email protected]</email>
</card>
<card>
<name>Fred Bloggs</name>
<email>[email protected]</email>
</card>
</addressBook>
`)const jsonSchema = relaxngToJsonSchema(rngSchema);
const jsonContent = xmlToJson(xmlContent, jsonSchema);function parseXML(input) {
return new DOMParser().parseFromString(input, "text/xml").documentElement;
}```
See full minimal working example in [demo/minimal.html](https://github.com/mbovel/relaxng-to-json-schema/blob/master/demo/minimal.html).
## Examples
Conversion examples can be found in the [`examples` directory](https://github.com/mbovel/relaxng-to-json-schema/tree/master/examples).
## Development setup
In order to use the library, you don't need to install anything as it is written in modern JavaScript directly understandable by modern browsers.
To run the tests, you will need to:
- Install [Node.js](https://nodejs.org/en/) **with a version higher than or equal to 13.8.0**,
- Install the dependencies by running `npm install` in this directory.