Generating

The AML renderer can be found in the Aml10Renderer class. All generation methods are asynchronous, and either returns a promise/future as a result.

Using the renderer the parsed generated JSON-LD document parsed by AMF for a AML dialect instance can be parsed and the original AML document regenerated.

Before parsing a dialect instance, the dialect must be registered using the AMF.registerDialect function.

Example

Java
JavaScript
package aml_org.examples;

import amf.client.AMF;
import amf.client.model.document.BaseUnit;
import amf.client.parse.AmfGraphParser;
import amf.client.render.Aml10Renderer;

import java.util.concurrent.ExecutionException;

import static java.lang.System.out;

public class Generating {

    //#generation-example
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        AMF.init().get();

        AMF.registerDialect("file://aml/music/dialect/playlist.yaml").get();

        BaseUnit playlist = new AmfGraphParser().parseFileAsync("file://aml/music/playlist1.json").get();

        String amlDocument = new Aml10Renderer().generateString(playlist).get();

        out.println(amlDocument);
    }
}


var amf = require("amf-client-js");
var AMF = amf.AMF;
var Aml10Renderer = amf.Aml10Renderer;
var AmfGraphParser = amf.AmfGraphParser;

//#generation-example
AMF.init()
    .then(function() {
        return AMF.registerDialect("file://aml/music/dialect/playlist.yaml")
    })
    .then(function() {
        return new AmfGraphParser()
            .parseFileAsync("file://aml/music/playlist1.json");
    })
    .then(function(unit) {
        return new Aml10Renderer().generateString(unit);

    })
    .then(function(amlDocument) {
        console.log(amlDocument);
    });

results matching ""

    No results matching ""