Parsing

The AML parser can be found in the Aml10Parser class. All parsing methods are asynchronous, and either returns a promise/future as a result.

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

Path examples

The paths given to the parser must have a specific structure:

Paths in Windows:

  • Absolute: file:///C:/testing/api.raml
  • Relative: file:///api.raml

Paths in Mac and Unix:

  • Absolute: file:///Users/aml/testing/api.raml
  • Relative: file://api.raml

Example

Java
JavaScript
package aml_org.examples;

import amf.client.AMF;
import amf.client.model.document.DialectInstance;
import amf.client.parse.Aml10Parser;

import java.util.concurrent.ExecutionException;

import static java.lang.System.out;

public class Parsing {

    //#parsing-example
    public static void main(String[] args) throws ExecutionException, InterruptedException {

        AMF.init().get();

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

        DialectInstance model = (DialectInstance) new Aml10Parser().parseFileAsync("file://aml/music/playlist1.yaml").get();

        displayEncodedElement(model);
    }

    static void displayEncodedElement(DialectInstance model) {
        out.println("Encoded element:");
        out.println("  " + model.encodes().id());
        out.println("Class terms for element:");
        for (String type : model.encodes().getTypeUris()) {
            out.println(" - " + type);
        }
    }

}


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

//#validation-example
AMF.init()
    .then(function() {
        return AMF.registerDialect("file://aml/music/dialect/playlist.yaml")
    })
    .then(function() {
        new Aml10Parser()
            .parseFileAsync("file://aml/music/playlist1.yaml")
            .then(displayEncodedElement);
    });

function displayEncodedElement(model) {
    console.log("Encoded element:");
    console.log("  " + model.encodes.id);
    console.log("Class terms for element:");
    model.encodes.getTypeUris().forEach(function(type) {
        console.log(" - " + type);
    });
}

results matching ""

    No results matching ""