XML

1 min read

Flowlet is native to JSON, which means that data flowing between blocks is JSON encoded. Support for XML is therefore provided by transformations based on a schema. Flowlet follows the OpenAPI specification for defining an XML schema.

const output = await xml.read('<user><name>John</name></user>', {
  type: 'object',
  properties: {
    name: {
      type: 'string'
    }
  }
});

The output will be {"name": "John"}. Similarly, the code below will result in the XML from the example above.

const output = await xml.write({name: 'John'}, {
  type: 'object',
  xml: {name: 'user'},
  properties: {
    name: {
      type: 'string'
    }
  }
});

Note that we have to provide a name for the root element. This is not mandatory when reading XML.