• Stars
    star
    345
  • Rank 122,071 (Top 3 %)
  • Language
    JavaScript
  • License
    BSD 2-Clause "Sim...
  • Created over 10 years ago
  • Updated almost 2 years ago

Reviews

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

Repository Details

Powerful XML<->JSON JavaScript mapping library.

Jsonix

  • Jsonix (JSON interfaces for XML) is a JavaScript library which allows you to convert between XML and JSON structures.
  • With Jsonix you can parse XML into JSON (this process is called unmarshalling) or serialize JSON in XML form (this is called marshalling).
  • These conversions are based on declarative XML/JSON mappings which can be written manually or generated from an XML Schema.

Jsonix advantages:

  • Strongly structured
  • Type-safe
  • Bidirectional
  • (Optionally) XML Schema-driven

See also the other Jsonix features.

Example

Here's a working example for the purchase order schema (try it online in JSFiddle).

Generate mappings

java -jar node_modules/jsonix/lib/jsonix-schema-compiler-full.jar
  -d mappings -p PO purchaseorder.xsd

Generates mappings for the purchaseorder.xsd schema in the mappings\PO.js; mappings will be placed in the variable PO.

Parse XML into JS

// Include or require PO.js so that PO variable is available
// For instance, in node.js:
var PO = require('./mappings/PO').PO;

// First we construct a Jsonix context - a factory for unmarshaller (parser)
// and marshaller (serializer)
var context = new Jsonix.Context([PO]);

// Then we create a unmarshaller
var unmarshaller = context.createUnmarshaller();

// Unmarshal an object from the XML retrieved from the URL
unmarshaller.unmarshalURL('po.xml',
    // This callback function will be provided
    // with the result of the unmarshalling
    function (unmarshalled) {
        // Alice Smith
        console.log(unmarshalled.value.shipTo.name);
        // Baby Monitor
        console.log(unmarshalled.value.items.item[1].productName);
    });

You can also unmarshalString, unmarshalDocument and (under node.js) unmarshalFile.

Serialize JS as XML

// Create a marshaller
var marshaller = context.createMarshaller();

// Marshal a JavaScript Object as XML (DOM Document)
var doc = marshaller.marshalDocument({
    name: {
        localPart: "purchaseOrder"
    },
    value: {
        orderDate: { year: 1999, month: 10, day: 20 },
        shipTo: {
            country: "US",
            name: "Alice Smith",
            street: "123 Maple Street",
            city: "Mill Valley",
            state: "CA",
            zip: 90952
        },
        billTo: { /* ... */ },
        comment: 'Hurry, my lawn is going wild!',
        items: { /* ... */ }
    }
});

You can also marshalString.

Jsonix Features

  • Runs in almost any modern browser
  • Runs in Node.js, package.json can be found here
  • Runs with CommonJS modules, AMD modules as well as vanilla (globals, without any module loader)
  • Bidirectional (XML -> JS as well as JS -> XML)
  • Implements marshalling (serializing the JavaScript object into XML)
    • Supports string data and DOM nodes as result
  • Implements unmarshalling (parsing a JavaScript object from XML)
    • Supports string data, DOM nodes, URLs or files (with Node.js) as source
  • Driven by declarative XML/JS mappings which control how JavaScript object is converted into XML or vice versa
  • Mappings can be automatically generated based on the XML Schema
  • Strongly-structured - XML/object mappings describe structures of JavaScript objects
  • Strongly-typed - Conversion between string content on XML side and values on the JavaScript side is controlled by declared property types
  • Provides extensible type system
    • Supports most XML Schema simple types (inlcuding QNames)
    • Supports enumerations, list and union simple types
    • Allows adding own simple types
    • Supports complex types consisting of several properties
    • Supports deriving complex types by extension
  • Provides advanced property system
    • Value, attribute, element, element reference properties for string processing of XML content
    • Any attribute, any element properties for "lax" processing for XML content

Documentation

Credits

Logo WebStorm

Jsonix is developed with WebStorm, the smartest JavaScript IDE.
Many thanks to JetBrains for providing a free open-source license for Jsonix development.

More Repositories

1

jaxb-tools

The most advanced JAXB2 Maven Plugin for XML Schema compilation.
Java
413
star
2

jsonix-schema-compiler

Compiles XML Schemas into XML<->JSON mappings for Jsonix.
Java
126
star
3

jaxb2-basics

Useful plugins and tools for JAXB2.
Java
105
star
4

ogc-schemas

XML<->Java and XML<->JS for OGC XSDs.
JavaScript
79
star
5

jaxb2-annotate-plugin

Add arbitrary annotations to JAXB classes.
Java
71
star
6

confluence-to-markdown-converter

Converts the Confluence storage format to Markdown format.
HTML
70
star
7

bahndata

Links auf die verfügbare Deutsche Bahn Daten
44
star
8

verbundkarte

Karte der Verkehrs- und Tarifverbünde in Deutschland
Batchfile
40
star
9

hyperjaxb3

Hyperjaxb3 provides relational persistence for JAXB objects
Java
34
star
10

bitcoin-a-day

Buy €X worth of Bitcoin a day using a cloud-scheduled task
Shell
27
star
11

db-fahrplan-api

Deutsche Bahn Fahrplan API
Java
14
star
12

w3c-schemas

XML<->Java (JAXB) and XML<->JS (Jsonix) bindings for W3C XML Schemas.
JavaScript
14
star
13

db-heartbeat

DB Heartbeat
JavaScript
13
star
14

raspberry-pi-adsb

Cheap and simple ADS-B base station for OpenSky Network
Shell
9
star
15

tenra

Tenra converts the railway network published by DB Netz in INSPIRE format into GeoJSON
Java
8
star
16

javascript-codemodel

Java
7
star
17

delays-api

API to find out train delays of the Deutsche Bahn.
Java
5
star
18

storyteller-maven-plugin

Java
5
star
19

camel-google-cloud-messaging

GCM Component for Apache Camel
Java
5
star
20

hvv-stops

Retrieves HVV stops as GTFS-compatible CSV
JavaScript
3
star
21

declension-dataset

Declined forms of German substantives
JavaScript
3
star
22

roads-to

Public transport "Roads to Rome"
Java
3
star
23

maven-jaxb2-plugin-support

Support project for maven-jaxb2-plugin
Java
3
star
24

postgis-verwaltungsgebiete

Scripts to setup a Postgis database with administrative areas of Germany
Batchfile
3
star
25

Germany-The-Beautiful-Travel-Country-1935-vs-1936

CSS
2
star
26

verwaltungsgebiete-bounding-boxes

Export bounding boxes of German administrative areas as CSV
Batchfile
2
star
27

aufzugswaechter

Java
2
star
28

annox

Parse Java annotations from text or XML resources.
Java
2
star
29

stop.direct

Shows departure board of the closes stop in Germany
Java
2
star
30

rail2ski

JavaScript
2
star
31

hotelroute

Find hotels with the best public transport connection to your destination
Java
2
star
32

iris-tts-rest

2
star
33

bahnhof.direct

Java
1
star
34

inspire-schemas

Batchfile
1
star
35

zugradar-scraper

Zugradar Scraper
Java
1
star
36

declension-alexa-skill-lambda

Alexa Declension Skill - Lambda
JavaScript
1
star
37

drunken-coder

What do we do with a drunken coder?
1
star
38

Mini_IndoorGMLFactory

Java
1
star
39

unece-maps

UNECE Maps
Batchfile
1
star
40

lombok-test

Trying to figure out a Lombok under Maven error
Java
1
star
41

lhapi-client

Java Client for LH API
Java
1
star
42

exjc

Extended XJC
1
star
43

aufzugswaechter-android-app

Android App for the Aufzugswaechter
Java
1
star
44

russian-railways-1867

Map of Russian Railways as of 1867
CSS
1
star
45

db-elevator-api-client

Java Client for DB S&S Elevators and Escalators API
Batchfile
1
star
46

reisezentren

1
star
47

streckenkarte

Streckenkarten des Fernverkehrs als Online-Karten
Batchfile
1
star
48

lhapi-specification

LH Public API OpenAPI Specification
1
star
49

jsonix-support

Jsonix Public Support Project
JavaScript
1
star
50

hafas-export-stops-by-coordinates

Exports stops from HAFAS by bounding box coordinates
JavaScript
1
star